-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
New C++ contour code with corner_mask kwarg #3874
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
Merged
Changes from all commits
Commits
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
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,25 @@ | ||
Changed behaviour of contour plots | ||
`````````````````````````````````` | ||
|
||
The default behaviour of :func:`~matplotlib.pyplot.contour` and | ||
:func:`~matplotlib.pyplot.contourf` when using a masked array is now determined | ||
by the new keyword argument `corner_mask`, or if this is not specified then | ||
the new rcParam `contour.corner_mask` instead. The new default behaviour is | ||
equivalent to using `corner_mask=True`; the previous behaviour can be obtained | ||
using `corner_mask=False` or by changing the rcParam. The example | ||
http://matplotlib.org/examples/pylab_examples/contour_corner_mask.py | ||
demonstrates the difference. Use of the old contouring algorithm, which is | ||
obtained with `corner_mask='legacy'`, is now deprecated. | ||
|
||
Contour labels may now appear in different places than in earlier versions of | ||
matplotlib. | ||
|
||
In addition, the keyword argument `nchunk` now applies to | ||
:func:`~matplotlib.pyplot.contour` as well as | ||
:func:`~matplotlib.pyplot.contourf`, and it subdivides the domain into | ||
subdomains of exactly `nchunk` by `nchunk` quads, whereas previously it was | ||
only roughly `nchunk` by `nchunk` quads. | ||
|
||
The C/C++ object that performs contour calculations used to be stored in the | ||
public attribute QuadContourSet.Cntr, but is now stored in a private attribute | ||
and should not be accessed by end users. |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python | ||
""" | ||
Illustrate the difference between corner_mask=False and corner_mask=True | ||
for masked contour plots. | ||
""" | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
# Data to plot. | ||
x, y = np.meshgrid(np.arange(7), np.arange(10)) | ||
z = np.sin(0.5*x)*np.cos(0.52*y) | ||
|
||
# Mask various z values. | ||
mask = np.zeros_like(z, dtype=np.bool) | ||
mask[2, 3:5] = True | ||
mask[3:5, 4] = True | ||
mask[7, 2] = True | ||
mask[5, 0] = True | ||
mask[0, 6] = True | ||
z = np.ma.array(z, mask=mask) | ||
|
||
corner_masks = [False, True] | ||
for i, corner_mask in enumerate(corner_masks): | ||
plt.subplot(1, 2, i+1) | ||
cs = plt.contourf(x, y, z, corner_mask=corner_mask) | ||
plt.contour(cs, colors='k') | ||
plt.title('corner_mask = {}'.format(corner_mask)) | ||
|
||
# Plot grid. | ||
plt.grid(c='k', ls='-', alpha=0.3) | ||
|
||
# Indicate masked points with red circles. | ||
plt.plot(np.ma.array(x, mask=~mask), y, 'ro') | ||
|
||
plt.show() |
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
Binary file added
BIN
+42.4 KB
lib/matplotlib/tests/baseline_images/test_contour/contour_corner_mask_False.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+53.9 KB
lib/matplotlib/tests/baseline_images/test_contour/contour_corner_mask_True.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
@ianthomas23 - does this actually get used? It is a complex piece of behaviour for not really that immediately obvious benefit (i.e. the rendering artifacts can really be quite prohibitive). Anyone else use it?
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've never used chunking myself, and I don't recall any questions about it on the mailing lists in the last few years. I presume it was originally used to work around limitations in some backends which could only accept arrays of points of some maximum size, but I don't know what the status of such limitations are now.
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.
We have the ability to simplify and split long paths before the render stage, so I'm not too sure how valuable the chunking actually is anymore. @WeatherGod do you use this? @mdboom - are my facts correct?
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 discussion certainly makes sense to me -- but I've never used
nchunk
personally. I think most of the backends (excepting probably Gdk) can handle really long paths now and the implicit simplification should help a lot with path length anyways. Maybe we deprecate it now and remove it later if no one complains? (Though I suspect no one will complain until after it's been removed ;)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've never used chunking; it was in the original algorithm, and when writing the wrapper I left it in in case it might be needed for very large, complex cases. I suspect that even now, some renderers (ps? pdf?) can bog down with extremely complex patches; but I don't have any examples.
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.
correct me if I am wrong, but the whole chunking thing is only associated with the legacy mode. So, it gets deprecated with the mode.
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.
@WeatherGod: you are wrong, consider yourself corrected!
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.
@ianthomas23 Took another look, and I see what you mean, I was looking at the calls to trace() and filled_polygons() and saw nchunks used in the former but not the latter. I see now that the new generator takes the nchunk argument directly.
But, in some respects, the intent behind the question still stands. We don't have to have the new generator take that argument, and relegate it completely to the legacy mode.