简体   繁体   English

如何设置刻度 label 格式为 10 的幂?

[英]How to set the tick label format as a power of 10?

I'm trying to plot a histogram with the ticklabel_format style as scientific.我正在尝试 plot 使用 ticklabel_format 样式作为科学的直方图。 But, I want the tick mark to appear as a power of 10, not 1e-2.但是,我希望刻度线显示为 10 的幂,而不是 1e-2。 Is there any way I can make the 1e-2 appear as 10^-2?有什么办法可以让 1e-2 显示为 10^-2?

在此处输入图像描述

PS: I'm using this for the first time. PS:我是第一次使用这个。 So please point out any mistakes or ways to improve my code.所以请指出任何错误或改进我的代码的方法。 Thanks in advance.提前致谢。

Code:代码:

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)

You need to use xscale or yscale and then fix the ticks您需要使用 xscale 或 yscale 然后修复刻度

plt.xscale('symlog') plt.xscale('symlog')

Checkout the example here: https://www.tutorialspoint.com/how-to-exponentially-scale-the-y-axis-with-matplotlib在此处查看示例: https://www.tutorialspoint.com/how-to-exponentially-scale-the-y-axis-with-matplotlib

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM