如何将刻度标签格式设置为10的幂?

时间:2020-02-06 14:13:58

标签: python matplotlib

我正在尝试将ticklabel_format样式的直方图绘制为科学的。但是,我希望刻度线显示为10的幂,而不是1e-2。有什么办法可以使1e-2显示为10 ^ -2?

enter image description here

P.S .:我第一次使用它。因此,请指出任何错误或改进我的代码的方法。预先感谢。

代码:

import matplotlib.pyplot as plt
time0=[]
with open("dist20_M500.dat") as f:
for line in f:
time0.append(float(line))
num_bins = 30
# the histogram of the data
n, bins, patches = plt.hist(time0, num_bins,  density = True, 
edgecolor='black', histtype='bar',facecolor='red', label = '$N=20$')
plt.xlabel(r'Time', fontsize=18)
plt.ylabel(r'$P(t)$', fontsize=18)
plt.legend()
plt.xticks(fontsize=16)
plt.yticks(fontsize=16) 
plt.ticklabel_format(style='sci', axis='both', scilimits=   
(0,0),fontsize=20)
plt.ticklabel_format(useOffset=False)

0 个答案:

没有答案