0

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.

enter image description here

Elad Weiss
  • 3,662
  • 3
  • 22
  • 50
  • Possible duplicate of [python/matplotlib - parasite twin axis scaling](https://stackoverflow.com/questions/3148808/python-matplotlib-parasite-twin-axis-scaling) – Diziet Asahi Feb 20 '18 at 12:58

1 Answers1

1

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 (e.g. by setting ax.margins or using the rcParam axes.ymargin), you need to modify the answer above with the relevant margin.

tmdavison
  • 64,360
  • 12
  • 187
  • 165