Skip to content
Advertisement

How to have a image as the plot face (the outer border) in matplotlib?

I know I can change the color using fig.patch.set_facecolor("#ccdece") but how do I have an image instead of a solid color? Like using img = plt.imread() and ax.imshow(img) but for the outer border.

Any help is welcome.

Advertisement

Answer

You can create a dummy ax for the full size of the surrounding figure and add an image to that ax. Giving the ax a low enough zorder makes sure it appears behind the actual plots.

For an additional effect, the facecolor of the actual plots can be made semi-transparent.

Here is an example starting from a stock image.

JavaScript

example figure background image

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement