如何设置y轴限制

新手上路,请多包涵

我需要有关在 matplotlib 上设置 y 轴限制的帮助。这是我尝试过的代码,但没有成功。

 import matplotlib.pyplot as plt

plt.figure(1, figsize = (8.5,11))
plt.suptitle('plot title')
ax = []
aPlot = plt.subplot(321, axisbg = 'w', title = "Year 1")
ax.append(aPlot)
plt.plot(paramValues,plotDataPrice[0], color = '#340B8C',
     marker = 'o', ms = 5, mfc = '#EB1717')
plt.xticks(paramValues)
plt.ylabel('Average Price')
plt.xlabel('Mark-up')
plt.grid(True)
plt.ylim((25,250))

使用此图的数据,我得到 20 和 200 的 y 轴限制。但是,我想要 20 和 250 的限制。

原文由 Curious2learn 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 291
1 个回答

通过 plt.gca() 获取当前轴,然后设置其限制:

 ax = plt.gca()
ax.set_xlim([xmin, xmax])
ax.set_ylim([ymin, ymax])

原文由 Hima 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题