我试图在matplotlib中绘制一个图形,包含5-5120之间的值,然而,它不是均匀缩放,而是像它应该的那样绘制一条漂亮的曲线,它不均匀地缩放x轴,使其看起来是线性的。
使用多轴缩放工具,但无济于事。在尝试更改轴时,我获得了此错误MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
# plotting the points
plt.plot(n, m)
# naming the x axis
plt.xlabel('X')
# naming the y axis
plt.ylabel('Y')
# giving a title to my graph
plt.title('test')
plt.axes().set_aspect(aspect=1)
# function to show the plot
plt.show()```
发布于 2019-08-30 11:46:08
我认为你需要使用plt.xticks(n)
import matplotlib.pyplot as plt
# plotting the points
n = [1,50, 250, 1000, 5210]
m = [1,2,3,4,5]
plt.plot(n, m)
# naming the x axis
plt.xlabel('X')
# naming the y axis
plt.ylabel('Y')
# giving a title to my graph
plt.title('test')
plt.xticks(n)
plt.show()
它显示的内容如下所示:
发布于 2019-08-30 17:40:45
您应该尝试使用:
plt.gca().set_aspect('equal', adjustable='box')
或
plt.axis('equal')
或
plt.axis('scaled')
https://stackoverflow.com/questions/57719517
复制