0

Is there a way to make it so that the panning function adjusts both the host and parasitic y axis and does not keep the parasitic axis fixed?

Example:

from mpl_toolkits.axes_grid1 import host_subplot
import mpl_toolkits.axisartist as AA
import matplotlib.pyplot as plt

host = host_subplot(111, axes_class=AA.Axes)

par1 = host.twinx()

new_fixed_axis = par1.get_grid_helper().new_fixed_axis

host.set_xlim(0, 2)
host.set_ylim(0, 2)

host.set_xlabel("Distance")
host.set_ylabel("Density")
par1.set_ylabel("Volume")

par1.axis['right'].toggle(all = True)

host.plot([0, 1, 2], [0, 1, 2])
par1.plot([0, 1, 2], [2, 4, 3])

plt.show()
Austin Russell
  • 417
  • 4
  • 17
  • Is there a reason to use `host_subplot` and `new_fixed_axis`? Otherwise I would recommend using normal subplots. Then using `twinx` automatically shares the axes to synchronize panning and zooming (in the shared direction). – ImportanceOfBeingErnest Oct 29 '17 at 22:20
  • @ImportanceOfBeingErnest Unfortunately, yes there is. My application has multiple parasitic axis not just the one attached one like in the example. – Austin Russell Oct 30 '17 at 15:07
  • 1
    What I mean is: Why create parasitic axes via `mpl_toolkits` and not via normal subplots? Everything is much easier using usual subplots. – ImportanceOfBeingErnest Oct 30 '17 at 15:11
  • I will find an example without using `mpl_toolkits` and see if i can rework the code. I will report back, thanks for the advice. – Austin Russell Oct 30 '17 at 15:17

1 Answers1

0

I took @ImportanceOfBeignErnest's advice and reworked the plots to not use the mpl_toolkits. I instead used splines to add additional axis. an example of this type of graph can be found here.

Austin Russell
  • 417
  • 4
  • 17