<div dir="ltr">I believe I saw an excellent example of this using Bokeh. There was a map, and you could drag a rectangle in it and have that area show up in a linked box. Also could move the rectangle around. Sorry for lack of information - it's on my work computer and I'm not there. I realize this does not use matplotlib, but it's good to know about alternative ways of doing things.</div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">----<br>Glenn Nelson in Santa Cruz<div>social: <a href="http://google.com/+GlennNelson" target="_blank">http://google.com/+GlennNelson</a><br>see my Kite Aerial Photos at <a href="http://www.glenn-nelson.us/kap" target="_blank">http://www.glenn-nelson.us/kap</a></div></div></div></div>
<br><div class="gmail_quote">On Thu, Mar 8, 2018 at 7:51 AM, Chad Parker <span dir="ltr"><<a href="mailto:parker.charles@gmail.com" target="_blank">parker.charles@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>All-<br><br></div>I frequently find myself trying to create plots that use a secondary axis to indicate data in a second set of units. For example, I might plot a data set with an x-axis in data number (e.g. the output of an analog to digital converter), and then wish to display the calibrated units on a secondary x-axis (e.g. volts).<br><br></div>There are quite a few examples that do this by creating a secondary axis using twiny(), and then setting the limits of the secondary x-axis to the scaled limits of the primary, and possibly setting the ticks to line up as well.<br><br></div><div>import matplotlib.pyplot as plt<br></div><div>import numpy as np<br></div><div>from scipy.stats import norm<br></div><div><br>f, ax = plt.subplots(1)<br></div><div>x_dn = np.arange(4096)<br></div><div>y = norm.pdf(x_dn, 2048, 64)<br><br></div><div>v = lambda x: x*5.0/4096<br></div><div><br></div><div>ax.plot(x_dn, y)<br>ax.grid(True)<br></div><div>ax_top = ax.twiny()<br>ax_top.grid(True)<br>ax_top.set_xticks([v(x) for x in ax.get_xticks()]) # optional, aligns the grids<br></div><div>ax_top.set_xlim([v(x) for x in ax.get_xlim()])</div><div><br></div><div>This isn't too painful if you're only doing it once. However, if you subsequently want to change the limits (from the command line) you have to explicitly set the limits of both axes or they will become out of sync (aside: they also can get out of sync if you set the secondary limits before the ticks, because setting the ticks can change the limits!). If you do set the ticks to line up the grids, then you also have to recompute those for the secondary axis.<br><br></div><div>ax.set_xlim([1500, 2500]) # now they're out of sync<br>ax_top.set_xticks([v(x) for x in ax.get_xticks()]) # ticks correct, but in wrong places<br>ax_top.set_xlim([v(x) for x in ax.get_xlim()]) # all's well again.<br><br></div><div>It just seems like there ought to be a better way. I apologize if it's out there and I missed it. <br><br></div><div>Thanks,<br></div><div>--Chad<br></div></div>
<br>______________________________<wbr>_________________<br>
Matplotlib-users mailing list<br>
<a href="mailto:Matplotlib-users@python.org">Matplotlib-users@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/matplotlib-users" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/matplotlib-<wbr>users</a><br>
<br></blockquote></div><br></div>