I would like to use the coordinate system of the figure rather than the axis to set the coordinates of the axes label (or if this is not possible at least some absolute coordinate system).
In other words I would like to the label at the same position for this two examples:
import matplotlib.pyplot as plt
from pylab import axes
plt.figure().show()
ax = axes([.2, .1, .7, .8])
ax.plot([1, 2], [1, 2])
ax.set_ylabel('BlaBla')
ax.yaxis.set_label_coords(-.1, .5)
plt.draw()
plt.figure().show()
ax = axes([.2, .1, .4, .8])
ax.plot([1, 2], [1, 2])
ax.set_ylabel('BlaBla')
ax.yaxis.set_label_coords(-.1, .5)
plt.draw()
plt.show()
Is this possible in matplotlib?
Yes. You can use transforms to translate from one coordinate system to another. There's an in-depth explanation here: http://matplotlib.org/users/transforms_tutorial.html
If you want to use figure coordinates, first you'll need to transform from figure coordinates to display coordinates. You can do this with fig.transFigure. Later, when you're ready to plot the axis, you can transform from display to axes using ax.transAxes.inverted().
import matplotlib.pyplot as plt
from pylab import axes
fig = plt.figure()
coords = fig.transFigure.transform((.1, .5))
ax = axes([.2, .1, .7, .8])
ax.plot([1, 2], [1, 2])
axcoords = ax.transAxes.inverted().transform(coords)
ax.set_ylabel('BlaBla')
ax.yaxis.set_label_coords(*axcoords)
plt.draw()
plt.figure().show()
coords = fig.transFigure.transform((.1, .5))
ax = axes([.2, .1, .4, .8])
ax.plot([1, 2], [1, 2])
ax.set_ylabel('BlaBla')
axcoords = ax.transAxes.inverted().transform(coords)
ax.yaxis.set_label_coords(*axcoords)
plt.draw()
plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With