gpt4 book ai didi

matplotlib - 如何在matplotlib中自动缩放y轴?

转载 作者:行者123 更新时间:2023-12-04 17:01:48 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Add margin when plots run against the edge of the graph

(1 个回答)


7年前关闭。




我目前正在创建许多图,有些看起来很棒,而另一些则需要进行一些调整。从下面如何让难以看到的情节线更容易看到而不必手动绘制它们?我一次绘制 50-100 个,然后将它们添加到 pdf 报告中。我想在线下添加空间,例如将 ylim min limit 设置为 -0.1,但会自动执行。

这是一个很难看到的情节线:
Hard to see plot line

这是一个很容易看到的情节线:
Easy to see plot line

这是我的绘图代码:

def plot(chan_data):
'''Uses matplotlib to plot a channel
'''
f, ax = plt.subplots(1, figsize=(8, 2.5))
x = dffinal['time'].keys()
ax.plot(x, dffinal[chan_data].values, linewidth=0.4, color='blue')
ax.xaxis.set_major_formatter(mdates.DateFormatter('%m/%d/%Y - %H:%M'))
ax.xaxis.set_major_locator(mdates.AutoDateLocator(interval_multiples=True))

lgd1 = ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))

f.autofmt_xdate()
ax.set_ylabel(dffinal[chan_data].name)
ax.grid('on')

#I've tried these with no luck
#ax.autoscale(enable=True, axis='y', tight=False)
#ax.set_ymargin(0.5)
#ax.set_autoscaley_on(True)

fname = ".\\plots\\" + chan_data + ".png"
print "Creating: " + fname
plt.savefig(fname, dpi=100, bbox_extra_artist=(lgd1,), bbox_inches='tight')
plt.close()
return fname

最佳答案

你要margins doc
前任

ax.margins(y=.1)
另见 Add margin when plots run against the edge of the graph

关于matplotlib - 如何在matplotlib中自动缩放y轴?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15375791/

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