如何在matplotlib图形中将点更改为逗号?

时间:2016-03-11 00:02:48

标签: python python-3.x numpy matplotlib comma

我希望将yticklabel小数点分隔符从小数点更改为逗号,但在使用this code或{{}中的代码后,保留偏移文本的格式(1e-14) 3}}

1

我的问题:

  1. 如何将点数更改为逗号并保存1e-14?
  2. 如何在偏移文本中将e更改为E
  3. 我正在使用Python 3.5

1 个答案:

答案 0 :(得分:5)

要将小数点分隔符从某个点更改为逗号,可以将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()

enter image description here

将偏移文本中的指数更改为E似乎不是一项简单的任务。您可以先查看答案here