matplotlib - How can I use MaxNLocator and specify a number which has to be in an axis?
<p>I do have a question with matplotlib in python. I create different figures, where every figure should have the same height to print them in a publication/poster next to each other.</p>

<p>If the y-axis has a label on the very top, this shrinks the height of the box with the plot. So I use MaxNLocator to remove the upper and lower y-tick. In some plots, I want to have the 1.0 as a number on the y-axis, because I have normalized data. So I need a solution, which expands in these cases the y-axis and ensures 1.0 is a y-Tick, but does not corrupt the size of the figure using tight_layout().</p>

<p>Here is a minimal example:</p>

<pre><code>import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator

x = np.linspace(0,1,num=11)
y = np.linspace(1,.42,num=11)

fig,axs = plt.subplots(1,1)
axs.plot(x,y)

locator=MaxNLocator(prune='both',nbins=5)
axs.yaxis.set_major_locator(locator)

plt.tight_layout()

fig.show()
</code></pre>

<p>Here is a <a href="https://depot.uni-konstanz.de/cgi-bin/exchange.pl?g=n4hq3y25kt" rel="nofollow">link</a> to a example-pdf, which shows the problems with height of upper boxline.</p>

<p>I tried to work with adjust_subplots() but this is of no use for me, because I vary the size of the figures and want to have same the font size all the time, which changes the margins. </p>

<p>Question is: </p>

<p>How can I use MaxNLocator and specify a number which has to be in the y-axis?</p>

<p>Hopefully someone of you has some advice.</p>

<p>Greetings,
Laenan</p>