Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It seems that you want to use a parasite axes with a specified scale. There is an <a href="http://matplotlib.org/examples/axes_grid/parasite_simple2.html" rel="nofollow noreferrer">example</a> of this on the matlpotlib site, slightly modified version is below.</p> <pre><code>import matplotlib.transforms as mtransforms import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1.parasite_axes import SubplotHost import numpy as np # Set seed for random numbers generator to make data recreateable np.random.seed(1235) # Define data to be plotted x1 = np.arange(0,10000,1000) x2 = x1/1000. y1 = np.random.randint(0,10,10) y2 = y1/5. # Create figure instance fig = plt.figure() # Make AxesHostAxesSubplot instance ax = SubplotHost(fig, 1, 1, 1) # Scale for top (parasite) x-axis: makes top x-axis 1/1000 of bottom x-axis x_scale = 1000. y_scale = 1. # Set scales of parasite axes to x_scale and y_scale (relative to ax) aux_trans = mtransforms.Affine2D().scale(x_scale, y_scale) # Create parasite axes instance ax_parasite = ax.twin(aux_trans) ax_parasite.set_viewlim_mode('transform') fig.add_subplot(ax) # Plot the data ax.plot(x1, y1) ax_parasite.plot(x2, y2) # Configure axis labels and ticklabels ax.set_xlabel('Original x-axis') ax_parasite.set_xlabel('Parasite x-axis (scaled)') ax.set_ylabel('y-axis') ax_parasite.axis['right'].major_ticklabels.set_visible(False) plt.show() </code></pre> <p>This gives the output below</p> <p><img src="https://i.stack.imgur.com/QEnou.png" alt="enter image description here"></p> <p>If you change the limits of the <code>ax</code> instance, the limits of the <code>ax_parasite</code> instance are updated automatically:</p> <pre><code># Set limits of original axis (parasite axis are scaled automatically) ax.set_ylim(0,12) ax.set_xlim(500,4000) </code></pre> <p><img src="https://i.stack.imgur.com/Wkm5f.png" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload