<div dir="ltr"><div>All-</div><div><br></div><div>I'm trying to do something similar to this example:</div><div><a href="https://matplotlib.org/examples/axes_grid/parasite_simple2.html">https://matplotlib.org/examples/axes_grid/parasite_simple2.html</a></div><div><br></div><div>However, instead of the parasite axes being overlaid with the primary one, I'd like it to be a separate subplot that I can put different data on. (Also, I'm trying to do this with a pair of y-axes, in case that's relevant. It's not immediately obvious how to adjust the example to do this with y instead of x.) Ultimately I want the second y-axis to set its range to some multiple of the first. So, for example, if I set one axis to have a y range of [0,64], I'd like the second subplot to automatically adjust its range to [0,32]. (I'd also like to be able to link the x axes to adjust together as normally done with the sharex keyword.)<br></div><div><br></div><div>My first thought was to modify the lines:</div><div>
<pre><span class="gmail-n">ax = SubplotHost(fig, 1, 1, 1)<br>...<br>ax_pm</span> <span class="gmail-o">=</span> <span class="gmail-n">ax_kms</span><span class="gmail-o">.</span><span class="gmail-n">twin</span><span class="gmail-p">(</span><span class="gmail-n">aux_trans</span><span class="gmail-p">)</span></pre>

</div><div>to be:</div><div>
<pre><span class="gmail-n">ax = SubplotHost(fig, 2, 1, 1)<br>...<br>ax_pm</span> <span class="gmail-o">=</span> <span class="gmail-n">fig.add_subplot(212, transform=</span><span class="gmail-p"></span><span class="gmail-n">aux_trans</span><span class="gmail-p">)</span></pre>

</div><div>but the result is a TypeError: unhashable type: 'Affine2D'. <br></div><div><br></div><div>Perhaps I'm getting transforms confused, and the transform keyword to add_subplot is used to define its location on the figure instead of how "twin" uses it to apparently scale the axes. The API just lists the keyword as expecting a type "Transform", and mentions that it's passed along to the Axes base class, which also just lists it as being of type "Transform".<br></div><div><br></div><div>(aside: is there documentation for the "SubplotHost" class? I don't see it listed here: <a href="https://matplotlib.org/3.1.1/api/_as_gen/mpl_toolkits.axes_grid1.parasite_axes.html">https://matplotlib.org/3.1.1/api/_as_gen/mpl_toolkits.axes_grid1.parasite_axes.html</a>  I went looking for the documentation of the "twin" function to see if I could understand how it used the transform, but was unable to find it in about 5 minutes of looking.)</div><div><br></div><div>To make it a little clearer what I'm after, here's some base code to set up an example:</div><div><br></div><div>import matplotlib.pyplot as plt<br><br>xdata = [1, 2, 3, 4, 5, 6]<br>ydata = [2, 4, 8, 16, 32, 64]<br>ydata2 = [y/2 for y in ydata]<br><br>fig = plt.figure()<br>ax1 = fig.add_subplot(2, 1, 1)<br>ax2 = fig.add_subplot(2, 1, 2, sharex=ax1)<br></div><div><br></div><div>ax1.plot(xdata, ydata)<br>ax2.plot(xdata, ydata2)<br></div><div><br></div><div>
# <somehow link the two y axes>

</div><div><br>ax1.set_ylim([0, 64])<br># ax2.set_ylim([0, 32])  # happens automagically with the previous line<br></div><div><br></div><div>It would be super convenient if one could simply pass a transform as the argument to sharey in the call to add_subplot...<br></div><div><br></div><div>Thanks for any help you might provide,</div><div>--Chad<br></div><div><br></div><div><br></div></div>