gpt4 book ai didi

python - Pyplot 不会停止显示 X 轴和 Y 轴的小数百分比

转载 作者:太空宇宙 更新时间:2023-11-03 15:18:11 53 4
gpt4 key购买 nike

我正在尝试使用 pyplot 进行线性建模,但遇到了问题。当我绘制数据图时,pyplot 希望沿 X 轴和 Y 轴放置小数百分比。我尝试了几种不同的方法来让它消失。我想保留一些刻度标签,所以我尝试了各种添加自己的刻度标签的方法,这很有效,但是,它仍然在顶部打印自己的刻度标签。

因此,在原点处它显示为 0.0,然后沿轴的五分之一处显示为 0.2,依此类推,直到轴的末端显示为 1.0。

问题的示例图像: Example image of the problem

fig = plt.figure(figsize = (10,10))
big_plot = fig.add_subplot(111)
data_plot = fig.add_subplot(211)
residual_plot = fig.add_subplot(212)
data_plot.plot(x,y,'ro')
data_plot.errorbar(x,model,sigma)
residual_plot.plot(x,residuals,'b*')
data_plot.set_title("Data")
data_plot.set_ylabel(y_label)
residual_plot.set_title("Residuals")
residual_plot.set_ylabel("Residual Value")
big_plot.set_xlabel(x_label)
plt.show()

有谁知道如何清除这些刻度标签并添加我自己的标签?谢谢。

最佳答案

在您的例子中,您正在创建三个图,但仅在其中两个上绘制数据。 big_plot 轴是使用默认刻度线绘制的,它是您不想要的额外刻度线的来源。

相反,只需删除该轴并通过将标签分配给 data_plot 来标记底部 x 轴即可。

fig = plt.figure(figsize = (10,10))
data_plot = fig.add_subplot(211)
residual_plot = fig.add_subplot(212)
data_plot.plot(x,y,'ro')
data_plot.errorbar(x,model,sigma)
residual_plot.plot(x,residuals,'b*')
data_plot.set_title("Data")
data_plot.set_ylabel(y_label)
residual_plot.set_title("Residuals")
residual_plot.set_ylabel("Residual Value")
data_plot.set_xlabel(x_label)
plt.show()

关于python - Pyplot 不会停止显示 X 轴和 Y 轴的小数百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43710125/

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