Is there a way to specify the edge for matplotlib's Rectangle patch so that the border is outside the domain specified? In photoshop, this is would be called "stroke position", for example. Allow me to illustrate with an example:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
# Here's my "image"
X = np.arange(16).reshape(4,4)
# Suppose I want to highlight some feature in the middle boxes.
fig = plt.figure()
ax = fig.add_subplot(111)
ax.imshow(X, cmap=plt.cm.gray, interpolation='nearest')
ax.add_patch( Rectangle((0.5, 0.5), 2, 2, fc='none', ec='r') )
plt.show()
This yields the following:

However, if modified the above as follows
ax.add_patch( Rectangle((0.5, 0.5), 2, 2, fc='none', ec='r', lw=10) )
I obtain the figure:

As you can see, the edge is center-positioned along the border of the domain of the Rectangle object, and so bleeds into this domain. Is it possible to force the edge border to be strictly outside the Rectangle's domain?

x,y. Which is clearly a hassle. Maybe there's something inpatheffects. - cphlewis(x,y)appropriately? I thought about something along those lines, butlinewidthseems to be based on the current figure size, not pixels. I can't seem to find in the documentation how this is specified: it only talks about "float value in points": matplotlib.org/api/… - Matt Hancockpatheffectsfor a bit which was informative about what Strokes can do: offsets but not, AFAICT, the kind of expansion and trapping that printing programs can do. I think adjusting thex,yis going to be necessary.) - cphlewispoints_to_pixelsmethod on some of the renderers, but I can't remember how you get from pixels to data-units except when printing. - cphlewis