Don't use removed QuadContourSet.collections in gallery example#7638
Don't use removed QuadContourSet.collections in gallery example#7638mkcor merged 2 commits intoscikit-image:mainfrom
QuadContourSet.collections in gallery example#7638Conversation
This was deprecated in matplotlib 3.8. I didn't really figure out an equivalent method that can use `set_label`. I usually got a "Legend does not support handles for QuadContourSet" error. So instead, I used proxy artists as suggested by https://matplotlib.org/stable/users/explain/axes/legend_guide.html#creating-artists-specifically-for-adding-to-the-legend-aka-proxy-artists Also update the API to use "import skimage as ski".
| ax[1].contour(evolution[2], [0.5], colors='g') | ||
| ax[1].contour(evolution[7], [0.5], colors='y') | ||
| ax[1].contour(evolution[-1], [0.5], colors='r') | ||
|
|
||
| # `Axes.legend` does not support handles for `QuadContourSet`, define proxy | ||
| # artists instead | ||
| contour_labels = [ | ||
| mlines.Line2D([], [], color="g", label="Iteration 2"), | ||
| mlines.Line2D([], [], color="y", label="Iteration 7"), | ||
| mlines.Line2D([], [], color="r", label="Iteration 35"), | ||
| ] |
There was a problem hiding this comment.
Can we pop this into a for-loop, and simplify the comment above contour_labels? I think the current text will be a bit confusing to newcomers, one of our target audiences. Perhaps something like "placeholder labels for contours" or similar.
There was a problem hiding this comment.
(I can also push the change, let me know.)
There was a problem hiding this comment.
There is also the legend_elements method, which essentially creates proxy artists for you.
There was a problem hiding this comment.
Thanks @rcomer; I tried that, but I couldn't figure out how to make it work in our case, since set_label doesn't seem to affect the returned label elements. Is there a way to set the label on each contour that way, so it comes back via legend_elements?
There was a problem hiding this comment.
I don’t think there is a way to set the labels on the contours. You can pass separate lists of handles and labels to legend though. So something like
handles = [cs.legend_elements()[0][0] for cs in contour_sets]
ax[3].legend(handles=handles, labels=labels)Whether that’s any less confusing than what you currently have, I’m not sure…
|
Take a look and see if you like this version (or not :D). |
|
Thanks @stefanv. I can't approve my own PR but consider it approved. ✔️ Feel welcome to merge @scikit-image/core to get the CI green again. |
Description
Fixes #7636.
This was deprecated in matplotlib 3.8. I didn't really figure out an equivalent method that can use
set_label. I usually got a "Legend does not support handles for QuadContourSet" error. So instead, I used proxy artists as suggested byhttps://matplotlib.org/stable/users/explain/axes/legend_guide.html#creating-artists-specifically-for-adding-to-the-legend-aka-proxy-artists
Also update the API to use "import skimage as ski".
Checklist
./doc/examplesfor new featuresRelease note
For maintainers and optionally contributors, please refer to the instructions on how to document this PR for the release notes.