I run into what seems to be a bug in matplotlib (version 1.4.3
)/pyplot when attempting to draw a line between subplots: after setting set_aspect("equal")
, it appears the relevant coordinate transformation functions (transData
) don't update. Execute the code below with ax.set_aspect("equal")
uncommented to see the difference.
import matplotlib.pyplot as plt
import matplotlib as mpl
f, (ax1, ax2) = plt.subplots(1, 2, sharey='all', sharex='all')
for ax in (ax1, ax2):
# ax.set_aspect("equal")
ax.set_ylim([-.2, 1.2])
ax.set_xlim([-.2, 1.2])
# From http://stackoverflow.com/questions/17543359/drawing-lines-between-two-plots-in-matplotlib
transFigure = f.transFigure.inverted()
coord1 = transFigure.transform(ax1.transData.transform([0,0]))
coord2 = transFigure.transform(ax2.transData.transform([1,0]))
line = mpl.lines.Line2D((coord1[0],coord2[0]),(coord1[1],coord2[1]),
transform=f.transFigure)
f.lines.append(line)
plt.show()