-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Incorrect polygon filling of mplot3d filled contouring #4784
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
Thanks. I had a feeling it was related to those issues, but wasn't sure. I'm happy to test any potential fixes. I'm trying to put together animations like this and the mis-fill is quite problematic. |
I've narrowed down the issue with this particular data a bit. If you do an but if you do an You can see similar results if you narrow the two contours to be 55.0 and 55.2. I'm going to be taking a look at the contourset returned by contourf and trying to pinpoint where it is going wrong. I'm assuming the return from Axes.contourf() is proper (since 2d plots are fine) and the issue is either in the transform to 3d or in the projection for drawing. |
Some more investigation! Using the same test data above and plotting except that This produces this miss-filled contour The dumped contents of This represented 2 distinct polygons with the larger one containing two holes. After the 3d projection (art3d.py:576), the In the second image you can see the lines that are causing the mis-fill. I'm still not familiar enough with the code to know how paths are determined to be lines or moves and the nuances of rendering but I'm continuing to dig and posting these updates in case anyone else can shed some light. |
@cwebster2: if you want some light shed, this is a well-known problem that has been hanging around since 2010. I wrote the following in PR #1928:
That PR contains a (poor quality) candidate fix that needs reworking by someone who knows something about the mplot3d codebase and cares about fixing such problems. No such person has come forward in the last couple of years. |
@ianthomas23 perfect! I think I skimmed across that earlier but forgot about it as a dove into the code. Thanks for pointing it out. I have a local branch that is probably 90% of your code but slightly reorganized. Once I regenerate my plots and make sure nothing blows up I'll see if I can clean it up any better and submit a PR. You saved a ton of time for me, thank you very much! (and this has been a longstanding problem with my 3d plots that I had chalked up to me doing something wrong before I looked more into it) |
Fixes matplotlib#4784 by adding path code information to the Poly3DCollection. This adds two new methods, path_to_3d_segment_with_codes and paths_to_3d_segments_with_codes which are meant to replace the versions without "_with_codes". A method was added to PolyCollection to allow Poly3DCollection to set vertices with path codes. This code was adapted from a PR by @ianthomas23.
Fixes matplotlib#4784 by adding path code information to the Poly3DCollection. This adds two new methods, path_to_3d_segment_with_codes and paths_to_3d_segments_with_codes which are meant to replace the versions without "_with_codes". A method was added to PolyCollection to allow Poly3DCollection to set vertices with path codes. This code was adapted from a PR by @ianthomas23.
Fixes matplotlib#4784 by adding path code information to the Poly3DCollection. This adds two new methods, path_to_3d_segment_with_codes and paths_to_3d_segments_with_codes which are meant to replace the versions without "_with_codes". A method was added to PolyCollection to allow Poly3DCollection to set vertices with path codes. This code was adapted from a PR by @ianthomas23.
Fixes matplotlib#4784 by adding path code information to the Poly3DCollection. This adds two new methods, path_to_3d_segment_with_codes and paths_to_3d_segments_with_codes which are meant to replace the versions without "_with_codes". A method was added to PolyCollection to allow Poly3DCollection to set vertices with path codes. Add image test for a case that causes improper polygon rendering without this fix. This code was adapted from a PR by @ianthomas23.
I have a dataset with large gradients in a quantity I am plotting. In many cases, this results in mis-filled contours when I use many contouring levels. For example:
This does not occur on 2D axes, even with 2 orders of magnitude more contouring levels. I can reduce some of the fill errors by reducing the number of contouring levels or zooming in on the domain so the strong gradients aren't as relatively strong in figure space. If I don't fill the contours, e.g. calling
contour
rather thancontourf
there are no errors. This is restricted to the filling,Here is a script that should reproduce the problem for you. Tested with matplotlib 1.4.3 and python 3.4.1.
which produces the image:
In this case, reducing the contouring level will fix the mis-fill but for the plots I want to produce this isn't a feasible option.
The text was updated successfully, but these errors were encountered: