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
When pcolorfast uses pcolorimage mode (i.e., for rectangular meshes with unequal spacing), an alpha keyword gets silently dropped even though there appears to be code to handle that in the definition of pcolorfast:
Well, I was planning to push some PRs to improve its functionality.
Specifically, right now it's a bit a pain to write robust code that works with imshow() independently of the setting of origin/rcParams["image.origin"] (see also https://matplotlib.org/devdocs/tutorials/intermediate/imshow_extent.html). Assume, for example, that the image x axis corresponds to xmin... xmax and the y axis corresponds to ymin... ymax. Then for imshow() to work independently of the origin, one needs to write something like
(+/-0.5's)
IOW the logical connection between indices and extents is not so great (plus one needs to remember whether it's xmin, xmax, ymin, ymax or xmin, ymin, xmax, ymax).
OTOH, pcolorfast makes the connection much more obvious:
pcolorfast((xmin, xmax), (ymin, ymax), data)
where ymin always corresponds to the first row of data and ymax to the last row.
Well of course right now pcolorfast has no "origin" kwarg, but that's the PR I'm preparing :)
seems like something better to point users towards, rather than a magic method that we will argue about the meaning of xmin for the next 10 years (i.e. is it the center of the pixel or the outer edge?).
But pcolormesh returns a QuadMesh, which is much less efficient than an AxesImage (it draws one quadrilateral at a time)... whereas pcolorfast (by design) detects the fast (regular) case and uses an AxesImage when possible.
I'm 👎 on having 3 (well actually 4 if we count pcolor) different methods that do subtly different things to accomplish the same goal. Two is fine (imshow and pcolormesh, I'd assume), but I'm against any modifications to pcolorfast. If you think imshow needs to be improved, I could see that argument.
In my view, the way origin, extent, and explicit x/ylimits play together in imshow() is close to beyond repair (the fact that you need a whole tutorial to understand how three kwargs interact with one another (https://matplotlib.org/devdocs/tutorials/intermediate/imshow_extent.html) seems just wrong), and is going to be very hard to fix with proper deprecations. So I'm basically exploiting pcolormesh as a new place to set up a more reasonable API...
My vote would be use imshow for basic stuff, and pcolormesh for more complicated. If you need extra performance, wrap imshow in whatever you need to get imshow to work. I don't see that imshow's brokenedness is a good reason to add more (breakable) API to pcolorfast.
Well, I can write my imshow wrapper but no one else will benefit from it, whereas improvements to pcolorfast would benefit everyone.
pcolormesh's API is also not totally compatible with pcolorfast, as it doesn't allow just passing (xmin, xmax), (ymin, ymax), but requires a full list of coordinates.
It's also not totally clear to me what you mean by breakability of the pcolorfast API.
What is the point of pcolorfast, other than you like x=(xmin, xmax), y=(ymin, ymax)?
I'd be very much against pcolorfast or anything else getting an origin kwarg like imshow currently has. The only reason its there is to accomodate users who don't know what np.flipud is, and if you can't google how to flip a matrix...
The problem of flipud is that now the indices on the matrix have changed, which is problematic if you want to point to someone else "oh, look at the feature at coordinates (42, 124)" (or if they already have a bunch of coordinates for you to look at, to plot over, etc.) and that someone else is using other software (e.g. MATLAB, cough cough -- $dayjob stuff; or it could even just be the orientation of the camera on some experimental bench) to visualize their data (and frankly it is easier for me to adapt my plots to match however MATLAB orients them and the camera's orientation, rather than to change other people's MATLAB code or to reorient the camera).
Again, I don't see what the big deal is. pcolormesh(np.random.randn(32,32)); ax.set_ylim(31, 0) gives you same thing explicitly that imshow does by default. My point is that the API in imshow tries to do too much, most of which would more elegantly by standard axis manipulation.
Again, beyond the slight API difference, what is the point of pcolorfast thats not provided by imshow (fast image dump) or pcolormesh?
From an API point of view, pcolormesh is much better than imshow (because it effectively allows setting the extents in a sane, origin-independent manner -- my y-axis is not necessarily 0-31, I can e.g. be zooming around a given pixel coordinates in a larger image), but from a performance point of view, pcolormesh is significantly slower for large images:
import timeit
from matplotlib import pyplot as plt
import numpy as np
shape = 640, 480
print("imshow")
fig, ax = plt.subplots()
ax.imshow(np.random.standard_normal(shape))
count, time = timeit.Timer("fig.canvas.draw()", globals={"fig": fig}).autorange()
print(time / count)
plt.close("all")
print("pcolormesh")
fig, ax = plt.subplots()
ax.pcolormesh(np.random.standard_normal(shape))
count, time = timeit.Timer("fig.canvas.draw()", globals={"fig": fig}).autorange()
print(time / count)
plt.close("all")
(Actually, for very small images, pcolormesh is a bit faster than imshow, which is a bit curious... I'll investigate.)
So once again, I'm treating pcolorfast as something with the performance of imshow (because it uses imshow in the case I care about, i.e. regular grid) but the saner extents API of pcolormesh.
After #13330 I can probably drop adding an origin kwarg (a standalone method is just fine).
As for the half-pixel ambiguity (#13328 (comment)), having (xmin, xmax) refer to pixel edges rather than pixel centers is consistent with both pcolor(mesh) and with the extents kwarg to imshow.
Having myself spent a significant amount of time finding an error in someone else's code that used imshow's extent the wrong way and caused camera image calibrations to fail, I can feel with anyone who has found for himself a good solution for such problem. If that is pcolorfast, so be it - it certainly is more intuitive in certain cases.
Concerning the initial issue, can PColorImage just error out when alpha is supplied and tell the user to use the slower method?
IIRC it's actually not that hard to make it support alpha, I must have the patch somewhere, just needs tests... and of course went down a rabbit hole of other "not really bugs but likely not optimal behavior" elsewhere.
I wrote pcolorfast for my own use case: plotting shipboard ADCP data, which is unevenly spaced in x but usually evenly spaced in y. The idea was to take advantage of the 3 levels of performance vs generality that others had already implemented: images are fast but not general, pcolormesh is general but not fast, and nonuniform image is in the middle, and applies to the most common nonuniform use case of rectilinear grids. I still think that supporting all 3 of these is well worth doing, and it is just a question of filling in the gaps, fixing the bugs, and ironing out the APIs. Work is needed on all three of these. Quadmesh is a marvel--but also a nightmare and a minefield, and pcolormesh wraps it in such a way that the land mines are sitting there, just waiting to blow off someone's foot.
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
Activity
jklymak commentedon Jan 30, 2019
Is there a reason to even keep
pcolorfastaround? I'd vote to deprecate it, unless there is some user base out there that depends on it...anntzer commentedon Jan 30, 2019
Well, I was planning to push some PRs to improve its functionality.
Specifically, right now it's a bit a pain to write robust code that works with imshow() independently of the setting of origin/rcParams["image.origin"] (see also https://matplotlib.org/devdocs/tutorials/intermediate/imshow_extent.html). Assume, for example, that the image x axis corresponds to xmin... xmax and the y axis corresponds to ymin... ymax. Then for imshow() to work independently of the origin, one needs to write something like
(+/-0.5's)
IOW the logical connection between indices and extents is not so great (plus one needs to remember whether it's xmin, xmax, ymin, ymax or xmin, ymin, xmax, ymax).
OTOH, pcolorfast makes the connection much more obvious:
where ymin always corresponds to the first row of data and ymax to the last row.
Well of course right now pcolorfast has no "origin" kwarg, but that's the PR I'm preparing :)
jklymak commentedon Jan 30, 2019
That seems like a whole method for a pretty narrow edge case.
pcolormeshtakes anxandyargument and removes half-pixel ambiguity:seems like something better to point users towards, rather than a magic method that we will argue about the meaning of
xminfor the next 10 years (i.e. is it the center of the pixel or the outer edge?).anntzer commentedon Jan 30, 2019
But pcolormesh returns a QuadMesh, which is much less efficient than an AxesImage (it draws one quadrilateral at a time)... whereas pcolorfast (by design) detects the fast (regular) case and uses an AxesImage when possible.
jklymak commentedon Jan 30, 2019
I'm 👎 on having 3 (well actually 4 if we count
pcolor) different methods that do subtly different things to accomplish the same goal. Two is fine (imshowandpcolormesh, I'd assume), but I'm against any modifications topcolorfast. If you thinkimshowneeds to be improved, I could see that argument.anntzer commentedon Jan 30, 2019
In my view, the way origin, extent, and explicit x/ylimits play together in imshow() is close to beyond repair (the fact that you need a whole tutorial to understand how three kwargs interact with one another (https://matplotlib.org/devdocs/tutorials/intermediate/imshow_extent.html) seems just wrong), and is going to be very hard to fix with proper deprecations. So I'm basically exploiting pcolormesh as a new place to set up a more reasonable API...
jklymak commentedon Jan 30, 2019
My vote would be use
imshowfor basic stuff, andpcolormeshfor more complicated. If you need extra performance, wrapimshowin whatever you need to getimshowto work. I don't see thatimshow's brokenedness is a good reason to add more (breakable) API topcolorfast.anntzer commentedon Jan 30, 2019
Well, I can write my imshow wrapper but no one else will benefit from it, whereas improvements to pcolorfast would benefit everyone.
pcolormesh's API is also not totally compatible with pcolorfast, as it doesn't allow just passing (xmin, xmax), (ymin, ymax), but requires a full list of coordinates.
It's also not totally clear to me what you mean by breakability of the pcolorfast API.
jklymak commentedon Jan 31, 2019
I wrote a longer post, but it boils down to:
What is the point of
pcolorfast, other than you likex=(xmin, xmax), y=(ymin, ymax)?I'd be very much against
pcolorfastor anything else getting anoriginkwarg likeimshowcurrently has. The only reason its there is to accomodate users who don't know whatnp.flipudis, and if you can't google how to flip a matrix...anntzer commentedon Jan 31, 2019
The problem of flipud is that now the indices on the matrix have changed, which is problematic if you want to point to someone else "oh, look at the feature at coordinates (42, 124)" (or if they already have a bunch of coordinates for you to look at, to plot over, etc.) and that someone else is using other software (e.g. MATLAB, cough cough -- $dayjob stuff; or it could even just be the orientation of the camera on some experimental bench) to visualize their data (and frankly it is easier for me to adapt my plots to match however MATLAB orients them and the camera's orientation, rather than to change other people's MATLAB code or to reorient the camera).
jklymak commentedon Jan 31, 2019
Again, I don't see what the big deal is.
pcolormesh(np.random.randn(32,32)); ax.set_ylim(31, 0)gives you same thing explicitly that imshow does by default. My point is that the API inimshowtries to do too much, most of which would more elegantly by standard axis manipulation.Again, beyond the slight API difference, what is the point of
pcolorfastthats not provided byimshow(fast image dump) orpcolormesh?anntzer commentedon Jan 31, 2019
From an API point of view, pcolormesh is much better than imshow (because it effectively allows setting the extents in a sane, origin-independent manner -- my y-axis is not necessarily 0-31, I can e.g. be zooming around a given pixel coordinates in a larger image), but from a performance point of view, pcolormesh is significantly slower for large images:
with agg
(mplcairo also has a slower pcolormesh).
(Actually, for very small images, pcolormesh is a bit faster than imshow, which is a bit curious... I'll investigate.)
So once again, I'm treating pcolorfast as something with the performance of imshow (because it uses imshow in the case I care about, i.e. regular grid) but the saner extents API of pcolormesh.
anntzer commentedon Feb 1, 2019
After #13330 I can probably drop adding an origin kwarg (a standalone method is just fine).
As for the half-pixel ambiguity (#13328 (comment)), having (xmin, xmax) refer to pixel edges rather than pixel centers is consistent with both pcolor(mesh) and with the extents kwarg to imshow.
ImportanceOfBeingErnest commentedon Feb 14, 2019
Having myself spent a significant amount of time finding an error in someone else's code that used imshow's
extentthe wrong way and caused camera image calibrations to fail, I can feel with anyone who has found for himself a good solution for such problem. If that ispcolorfast, so be it - it certainly is more intuitive in certain cases.Concerning the initial issue, can
PColorImagejust error out when alpha is supplied and tell the user to use the slower method?anntzer commentedon Feb 14, 2019
IIRC it's actually not that hard to make it support alpha, I must have the patch somewhere, just needs tests... and of course went down a rabbit hole of other "not really bugs but likely not optimal behavior" elsewhere.
efiring commentedon Feb 18, 2019
I wrote pcolorfast for my own use case: plotting shipboard ADCP data, which is unevenly spaced in x but usually evenly spaced in y. The idea was to take advantage of the 3 levels of performance vs generality that others had already implemented: images are fast but not general, pcolormesh is general but not fast, and nonuniform image is in the middle, and applies to the most common nonuniform use case of rectilinear grids. I still think that supporting all 3 of these is well worth doing, and it is just a question of filling in the gaps, fixing the bugs, and ironing out the APIs. Work is needed on all three of these. Quadmesh is a marvel--but also a nightmare and a minefield, and pcolormesh wraps it in such a way that the land mines are sitting there, just waiting to blow off someone's foot.
github-actions commentedon May 31, 2023
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
timhoffm commentedon May 31, 2023
We should at least warn on the ignored alpha.