Description
Bug report
Bug summary
The axes of a subplot_mosaic show up in a random order in fig.axes
(likely due to the use of a set
for uniquification in _identify_keys_and_nested
).
Code for reproduction
for _ in $(seq 10); do python -c 'from pylab import *; fig, axs = subplot_mosaic("ab"); print(fig.axes.index(axs["a"]))'; done
Actual outcome
1
0
1
1
1
0
0
0
0
1
Expected outcome
Axes should be added in a consistent order. I guess a reasonable one would be as if iterating the spec in C order (dropping duplicates).
Not release critical (especially as the order was not fixed, so fixing an order is not a backcompat break), but would be nice to get this sorted out before the API moves out of being experimental.
Matplotlib version
- Operating system: linux
- Matplotlib version (
import matplotlib; print(matplotlib.__version__)
): head - Matplotlib backend (
print(matplotlib.get_backend())
): any - Python version: 39
- Jupyter version (if applicable):
- Other libraries:
Note: the simple solution of replacing unique_ids = set()
by unique_ids = cbook._OrderedSet()
is good enough for the non-nested case, but doesn't handle nested layouts such as subplot_mosaic([["a", [["b1", "b2"], ["b3", "b4"]]], ["c", "d"]])
because currently the nested submosaic is always added after all the non-nested axes.