You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Hist2d is less sensitive to narrow bins in new version, resulting in different plots #23505
If you zoom in do the bands come back? Can you also check than np.histogram2d behaves the same with both numpy versions?
My knee-jerk diagnosis is that either something changed with how we are doing anti-aliasing on pcolormesh or have shifted something in the rendering by a few pixels so that it is hitting the AA code differently. If I am reading that right, there is something like 2-3x as many bins in the x-direction as there pixels available.
If you zoom in do the bands come back? Can you also check than np.histogram2d behaves the same with both numpy versions?
No they do not, at least not with png and in notebook.
That would actually be hard for me to do right now, but i think this can be excluded because:
My knee-jerk diagnosis is that either something changed with how we are doing anti-aliasing on pcolormesh or have shifted something in the rendering by a few pixels so that it is hitting the AA code differently. If I am reading that right, there is something like 2-3x as many bins in the x-direction as there pixels available.
It seems it must be the rendereing since when written to pdf both plots are roughly the same.
I think we just need a FAQ https://matplotlib.org/stable/users/faq/index.html for these sorts of issues. Basically if you have too many pixels we (or any rendering engine) have to decide which ones to show. We don't anti-alias pcolormesh cells like we do imshow.
@jklymak
I literally wouldn't have published a few papers If I would see the version from new matplotlib.
I don't know how this can be solved within the code, but i would strongly suggest going back to the previous rendering, since:
The new way hurts reproducibility of plots with matplotlib
Very crutial things on the plot can be missed in the way that the new plots are made.
AFAIK the anti-aliasing is for the plots to look nice, and if i would care for them looking nice i would opt for it, but good representation of the underlying data should take precedence.
It doesn't help matplotlib to be serious plotting library missing information from a plot because of a rendering issue (which wasn't there before).
For instance in the above, at least on my screen, the 3.5.1 version has more detail than the 3.3.4 version. Maybe you got them backwards, but regardless, you ideally will have two pixels for each bin, which for your plot means at least 275 dpi (4096 dots /15 inches). And practically you need more because your axes don't reach both sides of the figure, so round up to 300 dpi. Anything less and you will get aliasing.
I can confirm that snap=False gives the 3.3.4 behaviour.
The fundamental issue still remains that pcolormesh (or hist2d) with more bins than pixels is going to be aliased. I strongly recommend that folks who want to do raster outputs save in a quite high dpi and then reduce visually using an external package. Theoretically Matplotlib could do that, but currently we do not. For it to work properly you need the whole image to be composed in high definition and no matter what high definition you use, it will be too low for someone's plot.
Activity
jklymak commentedon Jul 28, 2022
Please make a reproducible minimal example. We can't test this as-is.
tacaswell commentedon Jul 28, 2022
If you zoom in do the bands come back? Can you also check than
np.histogram2dbehaves the same with both numpy versions?My knee-jerk diagnosis is that either something changed with how we are doing anti-aliasing on pcolormesh or have shifted something in the rendering by a few pixels so that it is hitting the AA code differently. If I am reading that right, there is something like 2-3x as many bins in the x-direction as there pixels available.
mmajewsk commentedon Jul 28, 2022
@jklymak
minimal code sample:
matplotlib 3.3.4
matplotlib 3.5.1
mmajewsk commentedon Jul 28, 2022
@tacaswell
No they do not, at least not with png and in notebook.
That would actually be hard for me to do right now, but i think this can be excluded because:
It seems it must be the rendereing since when written to pdf both plots are roughly the same.
jklymak commentedon Jul 28, 2022
I think we just need a FAQ https://matplotlib.org/stable/users/faq/index.html for these sorts of issues. Basically if you have too many pixels we (or any rendering engine) have to decide which ones to show. We don't anti-alias pcolormesh cells like we do imshow.
mmajewsk commentedon Jul 28, 2022
@jklymak
I literally wouldn't have published a few papers If I would see the version from new matplotlib.
I don't know how this can be solved within the code, but i would strongly suggest going back to the previous rendering, since:
It doesn't help matplotlib to be serious plotting library missing information from a plot because of a rendering issue (which wasn't there before).
jklymak commentedon Jul 28, 2022
The contention is you had a rendering issue in both versions, just that it was different.
jklymak commentedon Jul 28, 2022
For instance in the above, at least on my screen, the 3.5.1 version has more detail than the 3.3.4 version. Maybe you got them backwards, but regardless, you ideally will have two pixels for each bin, which for your plot means at least 275 dpi (4096 dots /15 inches). And practically you need more because your axes don't reach both sides of the figure, so round up to 300 dpi. Anything less and you will get aliasing.
If you use a pdf viewer it will anti-alias for you and do a better job of dealing with the singletons by averaging visual pixels. We do a version of that for imshow (https://matplotlib.org/stable/gallery/images_contours_and_fields/image_antialiasing.html) but we do not do that for pcolormesh rasters.
tacaswell commentedon Jul 28, 2022
Did we change something about drawing edges by default on pcolormesh?
jklymak commentedon Jul 28, 2022
Maybe? All I remember us working of for pcolormesh was the shading, which shouldn't affect this...
greglucas commentedon Jul 28, 2022
Snapping was changed, so maybe something related to that? #16090
jklymak commentedon Jul 29, 2022
@mmajewsk try setting snap=False to get the old (still aliased) behaviour.
jklymak commentedon Jul 29, 2022
I can confirm that
snap=Falsegives the 3.3.4 behaviour.The fundamental issue still remains that pcolormesh (or
hist2d) with more bins than pixels is going to be aliased. I strongly recommend that folks who want to do raster outputs save in a quite high dpi and then reduce visually using an external package. Theoretically Matplotlib could do that, but currently we do not. For it to work properly you need the whole image to be composed in high definition and no matter what high definition you use, it will be too low for someone's plot.jklymak commentedon Oct 26, 2022
I'm going to close this, because I don't think there is much we can do about this issue...