简体   繁体   中英

Adjusting y-axis scale in PyPlot

I have a PyPlot script that shows multiple plots. One of the plots (gpu) I wanted to scale down so I will see it in the lower part of the graph (as in the picture). In order to achieve this I set the axis ylim to 300.

if ymax is not None:
    ax.set_ylim(ax.get_ylim()[0], ymax)

The problem is that it messed up to lower ylim, and it is no longer in line with the rest of the axes. Any idea how I can fix that? Thanks.

在此处输入图片说明

This is because matplotlib by default adds a 5% margin to the data limits on the axes (since the style changes in matplotlib v2.0 ).

Let's say your data limits were 0100 , matplotlib would have added 5% on the top and bottom, so the axis limits would have been -5105 .

In your case, you have changed the upper limit to 300 , but not modified the lower margin.

So, you probably want to set the limits to -15315 , to be consistent with the others twin axes.

Note: Of course this relies on you using the default for ax.margins . If you have modified that (eg by setting ax.margins or using the rcParam axes.ymargin ), you need to modify the answer above with the relevant margin.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM