Hi, I'd like to use axhspan, but specifying both y *and*
> x extents in *data* units (by default, y is specified in
> data units, and x in axes -- relative 0-1 -- units). How
> should I proceed?
> I naively tried to play with gca().transAxes and so on,
> but I must admit I was utterly confused...
> Or should I directly draw a rectangle? (but how to?)
Yes, you should draw a rectangle. Eg,
from matplotlib.patches import Rectangle
r = Rectangle((left, bottom), width, height, facecolor='red')
ax.add_patch(r)
One thing to be aware of is that the axes datalimits are not updated
on a call to add_patch, so autoscaling may be off. You can update the
datalim yourself by doing
ax.update_datalim([(left, bottom), (right, top)])
and then
ax.autoscale_view()
It might be worth adding some convenience functions to draw basic
primitives like this, ie one would rather do
ax.rectangle((left, bottom), width, height, facecolor='red')
or
ax.circle((x,y), radius=5, edgecolor='green')
and not have to worry about the rest
JDH