Skip to content

Conversation

@nvaytet
Copy link
Member

@nvaytet nvaytet commented Nov 19, 2024

This adds two branches for plotting images: the old pcolormesh that can handle any coords, and a fast optimized branch that uses imshow to show images with linspace coords.

Fixes #392

@nvaytet nvaytet marked this pull request as ready for review March 13, 2025 15:35
@@ -0,0 +1,249 @@
# SPDX-License-Identifier: BSD-3-Clause
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file was moved basically without changes

**kwargs,
if all(
(data.coords[dim].ndim < 2)
and ((data.coords[dim].dtype == str) or (sc.islinspace(data.coords[dim])))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires that there are dim-coords for each dim. (Because it uses data.coords[dim].) Was this a requirement already before?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. If the input is missing them, some dummy (arange) coords are added before you get to here.
There are tests for this. See e.g.

def test_plot_data_array_missing_coords():

rasterized: bool = True,
**kwargs,
if all(
(data.coords[dim].ndim < 2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can FastImage handle scalar coords?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is a scalar coord that does not have the same name as a dimension

da = pp.data.data2d()
da.coords['scalar'] = sc.scalar(333., unit='K')
da.plot()

is fine (the 'scalar' coord is just ignored.

Interestingly, if the scalar coord is named 'x'

da = pp.data.data2d()
da.coords['x'] = sc.scalar(333., unit='K')
da

it fails, but also fails on main.

I can fix in another PR...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #425

@nvaytet nvaytet merged commit 354da05 into main Mar 14, 2025
4 checks passed
@nvaytet nvaytet deleted the fast-image branch March 14, 2025 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pcolormesh is slow: add an imshow optimized branch for linspace bins

3 participants