-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Turn ContourSet into a standard Collection artist. #25247
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
Merged
+3,191
−5,439
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
``ContourSet.collections`` | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
... is deprecated. `.ContourSet` is now implemented as a single `.Collection` of paths, | ||
each path corresponding to a contour level, possibly including multiple unconnected | ||
components. | ||
|
||
During the deprecation period, accessing ``ContourSet.collections`` will revert the | ||
current ContourSet instance to the old object layout, with a separate `.PathCollection` | ||
per contour level. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,9 +56,7 @@ | |
|
||
# We don't really need dashed contour lines to indicate negative | ||
# regions, so let's turn them off. | ||
|
||
for c in cset2.collections: | ||
c.set_linestyle('solid') | ||
cset2.set_linestyle('solid') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here this is much nicer :) |
||
|
||
# It is easier here to make a separate call to contour than | ||
# to set up an array of colors and linewidths. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately this change broke my "contours to shapefile" code, because the temporarily retained functionality of CountourSet.collections actually does not behave as it did before matplotlib 3.8.0. Somehow it is causing my final polygon set to become a single polygon, so that every contour has a connecting segment to the next contour in the set. So I was forced to update my code to the new definition of CountourSet, which I guess isn't a terrible thing, but effectively there is no "deprecation period"...it was immediate for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mstoelinga, please try our main branch and see if this is fixed for you. This was a mistake, and should be fixed in 3.8.1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the
collections
attribute actually couldn’t be fully backwards compatible (from this comment)matplotlib/lib/matplotlib/contour.py
Lines 967 to 970 in 518b268
There is now only one path in each collection, whereas there used to be multiple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds like something that could use contourpy directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very much so. I need to write up some docs on how to convert ContourPy outputs into other formats such as Shapely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am also looking for a solution to convert the
ContourSet
to shapefile. The code below does not work anymore.Any quick fix? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ougx does this help?
https://contourpy.readthedocs.io/en/latest/user_guide/external/shapely.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rcomer thanks. Are the plotted contours identical to what
ContourPy
generates?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ougx Matplotlib uses ContourPy's contours.