Conversation
Explicitly providing a single row and/or single column grid for pcolor(mesh) with nearest shading, silently produces no plot. This happens because nearest shading interprets the X and Y coordinates as cell centers and then calculates, from neighboring centers, new X and Y coordinates for the cell corners. When a coordinate array contains only one center, its corresponding cell size cannot be determined from neighboring centers. This commit adds a fallback that determines the directional cell size for a single center by taking half of its absolute value on either side. For a zero-valued center -/+ 0.5 is used instead. This allows the cells to be plotted. And a warning is emitted to notify the user.
|
As a rule, valid and intended usage patterns should not gernerate a warning, because that's annoying. A user must always have a way to write their code without warnings popping up. If we decide that single row is a valid use case, then we cannot plot and warn. For the concrete case we thus have the options:
|
|
Regarding a universal default for dX that would not need a warning, I'm unsure if a single fixed size would work well for the different types of coordinates that X can have have. I don't see an obvious default size that would be appropriate for all, so asking the user to supply the cell corners explicitly seems preferable. Then I'm leaning towards the first option of not supporting single row/column grids. |
|
Despite my previous comments, I wonder if this should be centred in the current axes viewport. The rationale being that someone may have already plotted something on the axes and we do not want the axes limits to change arbitrarily. Similarly that obviates concerns about datetimes. |
I don’t think that works well. It makes the effect of the command dependent on the previous state. Typically, we don’t want this. Also it’s a bit awkward that the coordinates are calculated from the viewport and then stored as data coordinates in the Artist. |
|
Well that is the point. If someone has already drawn something that got auto scaled to 1e-6 in the yin we don't want to plop something down that is width 0.5 on top. Of course the default would still be width 0.5 if the axes is empty |
That is fair. As is the desire to have a context independent behavior. As is the desire to draw “something reasonable” and not error out. We can’t have all three, so it’s a trade off decision we have to do. Do we have precedent for such a context dependent Artist creation? |
|
The current approach, and the one I understood from the discussion in the related issue to be reasonable, is to make a "good enough" guess of the cell size so as to plot something reasonable and, precisely because of this, have a warning. To remove the warning, the guess would have to stop being a "guess" and become a more careful assignment based on context. From what I imagine, it would need to check whether the axes is empty (use its view limits if not?), whether the axis has units (dates, categoricals), whether the axis is logarithmically scaled, etc. I do not know any Artist creation precedents that depend on context. IMO, this approach is not worth it. The puristic approach of not supporting single row/column grids seems to have the best tradeoff to me. The operation would raise an error but the semantics of nearest shading get well established for this case, and the user has full control over the grid by supplying cell edges instead. Also, this approach makes sense technically from how the shading works and how cell edges are determined from cell centers. I maintain my preference for this approach. However, the approach of fully validating the use case of single row/column grids, by letting the user control the behavior with a new parameter seems interesting. |
No, and I guess we don't like doing things that depend on order of artist creation, so I withdraw my idea. I think given the issues with this, probably there should just be an error. |
PR summary
Closes #25699
Explicitly providing a single row and/or single column grid for pcolor(mesh) with nearest shading, silently produces no plot.
This happens because nearest shading interprets the X and Y coordinates as cell centers and then calculates, from neighboring centers, new X and Y coordinates for the cell corners. When a coordinate array contains only one center, its corresponding cell size cannot be determined from neighboring centers.
This PR adds a fallback that determines the directional cell size for a single center by taking half of its absolute value on either side. For a zero-valued center -/+ 0.5 is used instead. This allows the cells to be plotted. And a warning is emitted to notify the user.
AI Disclosure
Had AI help me understand parts of the logic of the interp_grid() function.
PR quality check