python - Set axes label in coordinate system of figure rather than axes -


i use coordinate system of figure rather axis set coordinates of axes label (or if not possible @ least absolute coordinate system).

in other words label @ same position 2 examples:

import matplotlib.pyplot plt 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 possible in matplotlib?

illustrate difference

yes. can use transforms translate 1 coordinate system another. there's in-depth explanation here: http://matplotlib.org/users/transforms_tutorial.html

if want use figure coordinates, first you'll need transform figure coordinates display coordinates. can fig.transfigure. later, when you're ready plot axis, can transform display axes using ax.transaxes.inverted().

import matplotlib.pyplot plt 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() 

Comments