gpt4 book ai didi

python - 如何设置y轴限制

转载 作者:IT老高 更新时间:2023-10-28 12:06:16 24 4
gpt4 key购买 nike

我需要帮助来设置 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。

最佳答案

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

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

关于python - 如何设置y轴限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3777861/

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