[英]How to set the tick label format as a power of 10?
我正在尝试 plot 使用 ticklabel_format 样式作为科学的直方图。 但是,我希望刻度线显示为 10 的幂,而不是 1e-2。 有什么办法可以让 1e-2 显示为 10^-2?
PS:我是第一次使用这个。 所以请指出任何错误或改进我的代码的方法。 提前致谢。
代码:
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)
您需要使用 xscale 或 yscale 然后修复刻度
plt.xscale('symlog')
在此处查看示例: https://www.tutorialspoint.com/how-to-exponentially-scale-the-y-axis-with-matplotlib
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.