Matplotlib squishes axis labels when setting labels on twiny() axis
<p>I'm trying to add a second set of tic marks to my plot. I'm getting the original tic marks with <code>get_xticks()</code>, converting them to what I want (in this example simply adding 100) and calling <code>set_xticks()</code> on an axis I got from <code>ax.twiny()</code>.</p>

<p>When I do this, my twin axis labels are all crammed to the right as seen in the top right of the graph. </p>

<p>Here's the code I used:</p>

<pre><code> ax2 = ax.twiny()
 ax2.set_xticks(ax.get_xticks()+100)
</code></pre>

<p><a href="http://i.stack.imgur.com/LyAAA.png" rel="nofollow"><img src="http://i.stack.imgur.com/LyAAA.png" alt="enter image description here"></a></p>

<p>FYI:</p>

<pre><code> print(ax.get_xticks())
 [  950.  1000.  1050.  1100.  1150.  1200.  1250.]
</code></pre>

<p>Try this (incomplete code; needs to be merged with OPs):</p>

<pre><code>from matplotlib.ticker import FuncFormatter
def shift(x, pos):
    return x+100
formatter = FuncFormatter(shift)

ax2 = ax1.twiny()
ax2.xaxis.set_major_formatter(formatter)
ax2.set_xlim(ax1.get_xlim())
</code></pre>

<p>Read also <a href="http://stackoverflow.com/questions/13772673/matplotlib-imshow-twiny-problems">this question</a>.</p>

python matplotlib plot