In Matplotlib, in many drawing and configuration methods, you can set the zorder
keyword to determine which elements are drawn on top of which ones. Now, my application would require a specific kind of handling or zorder
as follows:
- Element A is drawn on top of element B
- Element B is drawn on top of element C
- Element C is drawn on top of element A
in a cyclic manner, like in rock-paper-scissors (A
on top of B
on top of C
on top of A
------- Rock
beats Scissors
beats Paper
beats Rock
). I.e. there is no absolute zorder, but only pairwise.
- Element A is
ax.imshow
- Element B is
ax.fill_between
- Element C is
ax.grid
In addition, element D is a plot drawn on top of everything else, but that is easy to implement when the rest is working.
Particularly, Element C i.e. the grid should be below everything except element B, the fill_between
, which however should cover element A, the imshow
from matplotlib import pyplot as plt
import matplotlib.figure
fig = matplotlib.figure.Figure()
ax = fig.subplots()
x, y, X = ... # some data, details do not matter here
ax.plot(x, y, zorder=???) # Element D
ax.imshow(X, ..., zorder=???) # Element A
ax.fill_between(x, y, zorder=???) # Element B
ax.set_axisbelow(True) # Set True or False, does it matter?
ax.grid(..., zorder=???) # Element C
For details and context, this is related to Matplotlib - color under curve based on spectral color where a grid should be below the rainbow but above the white area.