在 matplotlib 中设置 y 轴限制 [英] setting y-axis limit in matplotlib
本文介绍了在 matplotlib 中设置 y 轴限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要关于在 matplotlib 上设置 y 轴限制的帮助.这是我尝试过的代码,但没有成功.
I need help with setting the limits of y-axis on matplotlib. Here is the code that I tried, unsuccessfully.
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.
With the data I have for this plot, I get y-axis limits of 20 and 200. However, I want the limits 20 and 250.
推荐答案
通过plt.gca()
获取当前坐标轴,然后设置它的界限:
Get current axis via plt.gca()
, and then set its limits:
ax = plt.gca()
ax.set_xlim([xmin, xmax])
ax.set_ylim([ymin, ymax])
这篇关于在 matplotlib 中设置 y 轴限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文