【发布时间】:2016-06-26 01:57:40
【问题描述】:
我想在使用this code 或that code 的代码后将yticklabel 小数点分隔符从小数点更改为逗号,但保留偏移文本的格式 (1e-14)。
我的问题:
- 如何将点改为逗号并保存 1e-14?
- 如何将偏移文本中的
e更改为E?
我正在使用 Python 3.5
【问题讨论】:
标签: python python-3.x numpy matplotlib comma
我想在使用this code 或that code 的代码后将yticklabel 小数点分隔符从小数点更改为逗号,但保留偏移文本的格式 (1e-14)。
我的问题:
e 更改为E? 我正在使用 Python 3.5
【问题讨论】:
标签: python python-3.x numpy matplotlib comma
要将小数点分隔符从点更改为逗号,您可以将locale 更改为使用逗号的位置。例如,这里我设置为德语:
#Locale settings
import locale
# Set to German locale to get comma decimal separater
locale.setlocale(locale.LC_NUMERIC, "de_DE")
import numpy as np
import matplotlib.pyplot as plt
plt.rcdefaults()
# Tell matplotlib to use the locale we set above
plt.rcParams['axes.formatter.use_locale'] = True
# make the figure and axes
fig,ax = plt.subplots(1)
# Some example data
x=np.arange(100)
y=4e-18*x**2
# plot the data
ax.plot(x,y,'b-')
plt.show()
将偏移文本中的指数更改为E 似乎不是一项简单的任务。你可以先看看答案here。
【讨论】:
locale.setlocale(locale.LC_NUMERIC, ('pl_PL', 'UTF-8'))。我想知道您的回复中是否不应该是('de_DE', 'UTF-8') 或 'de_DE.UTF-8'(也许它取决于操作系统?)。