I am totally stumped at how to use parasite axes using the OO API (Figure embedded in PyQt4). I want to plot an axis offset from the plot as per the code below. However when embedding matplotlib in PyQt4 one can't use pyplot or host_subplot.
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)
plt.subplots_adjust(right=0.75)
par1 = host.twinx()
par2 = host.twinx()
offset = 60
new_fixed_axis = par2.get_grid_helper().new_fixed_axis
par2.axis["right"] = new_fixed_axis(loc="right",
axes=par2,
offset=(offset, 0))
par2.axis["right"].toggle(all=True)
host.set_xlim(0, 2)
host.set_ylim(0, 2)
par1.set_ylabel("Temperature")
par2.set_ylabel("Velocity")
p2, = par1.plot([0, 1, 2], [0, 3, 2], label="Temperature")
p3, = par2.plot([0, 1, 2], [50, 30, 15], label="Velocity")
par1.set_ylim(0, 4)
par2.set_ylim(1, 65)
plt.draw()
plt.show()
I did manage to plot an offset axis by creating two Figures and linking their axes as per the question here:
Matplotlib show one axis and no data
This is my preferred method as it allows me to put a QSplitter between the figures, however I cannot get the upper plot to show the X axis only - some of the graph plot and its data always show no matter how small I set the y axis to be.
I then tried drawing my own offset axis in a separate QWidget by obtaining the plots axis geometry:
ax = foo.figure.add_subplot(1,1,1)
lineGeometry = [ax.bbox.x0, etc.]
then using the axis geometry to draw a line with Qt.QPainter() the same start/end position but offset from the plot in a separate QWidget. This is a bit clunky and I would prefer a simpler way.
Any help with using parasitic axes embedded in Qt4 would be appreciated.