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. |
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