Given a matplotlib figure or plot, how can I retrieve the value of the highest zorder object? For instance, retrieving the value of 5 in this example:
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(1)
ax.plot(np.arange(10), np.arange(10), zorder=5, linewidth=5)
ax.plot(np.arange(10), np.arange(10)[::-1], zorder=1, linewidth=5)
# implement: get_maximum_zorder(ax)

This can be done by accessing the axes's children, each of which has a zorder attribute.
max([_.zorder for _ in ax.get_children()])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With