使用matplotlib中的裕量自动缩放 [英] Autoscale with margin in matplotlib
本文介绍了使用matplotlib中的裕量自动缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为了使用 matplotlib 绘制带有自动缩放轴的图,我使用以下代码:
In order to have a plot with autoscale axes with matplotlib, I use this code:
axes.set_autoscale_on(True)
axes.autoscale_view(True,True,True)
效果很好,我有这个情节:
It works well, and I have this plot:
但我希望顶部有一个边距,即在我的示例中,我希望 y 轴上升到 11 而不是 10.你知道怎么做吗?
But I'd like to have a margin on the top, i.e. in my example I'd like the y axe goes up to 11 instead of 10. Do you know how to do that?
推荐答案
试试下面的代码:
axes.set_autoscale_on(True)
axes.autoscale_view(True,True,True)
axes.set_ylim(0, 11) # 11 -> max(yvalues) + 1
这篇关于使用matplotlib中的裕量自动缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文