python plotting with twiny() doesn't position ticks and destroys aspect-ratio
<p>I have created a function to plot many similar plots of contours. I am showing the minimal form of what I am doing. In this minimal example I would like to put only ticks at (0,0) A, (3,0) B, (3,3) C, (0,3) D, where A,B,C,D the labels of the ticks. I can get it to work up to putting A and B. When I introduce <code>twiny()</code> to create C and D ticks nothings seams to work any-more. Ticks are not placed where expected, and aspect ration is destroyed. I tried using <code>host_subplot</code> from <code>mpl_toolkits.axes_grid1</code>, but it didn't fix this.</p>

<pre><code>import matplotlib
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt

def plot2DFS(fign,x,y,z):

    fig = plt.figure(fign)
    ax = fig.add_subplot(111, adjustable='box-forced', aspect='equal')
    ax.set_title('Iso-surf contour')
    ax.contour(x, y, z)

    ax.spines['left'].set_position('center')
    ax.spines['right'].set_color('none')
    ax.spines['bottom'].set_position('center')
    ax.spines['top'].set_color('none')

    ax.tick_params(axis='y',which='both', right='off', left='off', labelleft='off')
    ax.tick_params(axis='x',which='both', bottom='off', top='off')

    ax.xaxis.set_ticks([0.0,3.0])
    ax.xaxis.set_ticklabels(['A','B'])

    bx = ax.twiny()
    bx.tick_params(axis='x',which='both', bottom='off', top='off')
    bx.xaxis.set_ticks([0.0,3.0])
    bx.xaxis.set_ticklabels(['D','C'])

    return

delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
plot2DFS(1,X,Y,Z)
plt.show()
</code></pre>

<p>The aspect ratio is just fine, you see a perfect circle, don't you?</p>

<p>Concerning the labels and their position you need to tell matplotlib that you want equal x limits. Put <code>bx.set_xlim(ax.get_xlim())</code> at the end of your function.</p>

python matplotlib aspect-ratio