使用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