gpt4 book ai didi

python - 如何在matplotlib中设置轴的单位长度?

转载 作者:太空狗 更新时间:2023-10-29 20:54:39 29 4
gpt4 key购买 nike

例如 x = [1~180,000]当我绘制它时,在 x 轴上,它显示:1, 20,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()

enter image description here

关于python - 如何在matplotlib中设置轴的单位长度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10703813/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com