matplotlib add rectangle to Figure not to Axes

matplotlib, python

Solution

You can use a phantom axes on top of your figure and change the patch to look as you like, try this example:

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
ax.xaxis.set_visible(False)
ax.yaxis.set_visible(False)
ax.set_zorder(1000)
ax.patch.set_alpha(0.5)
ax.patch.set_color('r')

ax2 = fig.add_subplot(111)
ax2.plot(range(10), range(10))

plt.show()

Problem

I need to add a semi transparent skin over my matplotlib figure. I was thinking about adding a rectangle to the figure with alpha <1 and a zorder high enough so its drawn on top of everything. I was thinking about something like that ``` figure.add_patch(Rectangle((0,0),1,1, alpha=0.5, zorder=1000)) ``` But I guess rectangles are handled by Axes only. is there any turn around ?

Original source