Reputation: 2360
I'm trying to plot over an watermark using figimage
, but no matter what I do, the image ends up on top of the plot.
Here is my code:
import numpy as np
import matplotlib.pyplot as plt
im = np.zeros((40,40,3), dtype=np.float)
fig, ax = plt.subplots()
fig.figimage(im, 100, 60)
plt.scatter([0, 1, 2, 3, 4], [0, 1, 2, 3, 4], zorder=10)
plt.show()
I've tried using the zorder
argument, but that doesn't work either. Any idea how I can get an image behind the plot?
Upvotes: 0
Views: 1401
Reputation: 339280
zorder
is indeed the way to go here. You will want the axes to have a higher zorder than the image. (This is because the figimage
is a child of the figure, not the axes.)
So,
ax.set_zorder(1)
im.set_zorder(0)
puts the image behind the axes. Now that may be undesired, because it's hidden. So in addition you would then need to make the axes background transparent.
import numpy as np
import matplotlib.pyplot as plt
im = np.zeros((40,40,3), dtype=np.float)
fig, ax = plt.subplots()
im = fig.figimage(im, 100, 60)
ax.scatter([0, 1, 2, 3, 4], [0, 1, 2, 3, 4])
ax.set_zorder(1)
im.set_zorder(0)
ax.patch.set_visible(False)
plt.show()
Upvotes: 2