-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Doc]: ContourSet
allsegs
and allkinds
after #25247
#26863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Yes this is a major change that needs better documentation if possible. I ran into this just yesterday trying to make kmls for Google earth out of Matplotlib contours. I recall discussion about this being better done directly in contourpy now but was unsure how to proceed. It may be good for a doc update to describe how to do this in contourpy or link to the appropriate place in contourpy. @ianthomas23 @anntzer i think you were the proponents of this change? |
I think the init for ContourSet is probably still correct, just that the temporary shim for the properties has now changed the shape? This came in #25138 |
@zmoon, did you have a test case for this? |
From a quick look (untested...) I would agree with @jklymak's comment, i.e. the init allsegs/allkinds is still a list of polygons/of polygon codes unlike the attribute (but note that even in the init you can pass all the polygons together as a single "polyline" including the relevant CLOSEPOLY & MOVETO codes in allkinds). |
As for whether to use Matplotlib or ContourPy to calculate your contours, it depends on your use case. If you are rendering them in Matplotlib as well as doing something else such as transforming the coordinates or extracting some statistics about the lines/polygons, then use Matplotlib. Otherwise use ContourPy directly so that you don't have to concern yourself with Matplotlib Figures, Axes and path codes. You have choice in how the contour data is returned to you, and it will be both simpler and faster.
The Matplotlib contouring functions already link to ContourPy. There isn't an appropriate place in the ContourPy docs to link, it is all of the docs. They are short, the library only does one thing. |
OK, the question is if we meant to make the contours harder to parse in Matplotlib? Because currently we no longer return a list of segments for each level in |
The If we want to make it easier to get hold of individual segments we could make _iter_connected_components public? |
Agreed that is the deprecation, but decoding paths is a lot harder than dealing with a list segments. Given that contourpy returns a list of segments I think it would be nice if we made that available to users. It seems that is where we were before the deprecation, so perhaps it should be reconsidered? |
Finally got a chance to test this: x, y = np.meshgrid(np.arange(0, 10, 2), np.arange(0, 10, 2))
z = np.sin(x) * np.cos(y)
plt.figure(figsize=(6, 2), dpi=200)
cs = plt.contour(x, y, z, levels=[0, 0.5])
print(cs.allsegs) 3.7.2:
3.8.0:
So clearly the new allsegs is very different from the old - I think this needs to be fixed for anyone who needed the old one, even if it is now deprecated. Whether we keep the deprecation is a less urgent question, but if we do, then I think we need to provide someway of getting this information. |
Documentation Link
https://matplotlib.org/stable/api/contour_api.html
Problem
It seems that their descriptions are no longer accurate after #25247.
For example
matplotlib/lib/matplotlib/contour.py
Lines 719 to 726 in dceb278
Now,
level0segs
(.allsegs[0]
) is justpath0
(single Nx2 array of vertices for all contours for level 0), not[polygon0, polygon1, ...]
.Suggested improvement
No response
The text was updated successfully, but these errors were encountered: