例如x = [1~180,000]当我绘制它时,在x轴上,它显示:1,200,000,40,000,... 180,000这些0真的很烦人
如何将x轴的单位长度更改为1000,以便显示:1,20,40,... 180并显示其单位为1000的某个位置.
我知道我自己可以进行线性转换.但是在matplotlib中是不是有一个函数呢?
如果您的目标是制作出版物质量数据,则需要对轴标签进行精细控制.一种方法是提取标签文本并应用您自己的自定义格式:
import pylab as plt
import numpy as np
# Create some random data over a large interval
N = 200
X = np.random.random(N) * 10 ** 6
Y = np.sqrt(X)
# Draw the figure to get the current axes text
fig, ax = plt.subplots()
plt.scatter(X,Y)
ax.axis('tight')
plt.draw()
# Edit the text to your liking
label_text = [r"$%i \cdot 10^4$" % int(loc/10**4) for loc in plt.xticks()[0]]
ax.set_xticklabels(label_text)
# Show the figure
plt.show()
Run Code Online (Sandbox Code Playgroud)
