Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip plotting line data if it's all NaNs #802

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/802.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Skip plotting line data if all values are NaN
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Skip plotting line data if all values are NaN
Make `~ndcube.visualization.mpl_plotter.MatplotlibPlotter` only add data to line plots if at least one value of the data is unmasked and finite.

4 changes: 3 additions & 1 deletion ndcube/visualization/mpl_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ def _plot_1D_cube(self, wcs, axes=None, axes_coordinates=None, axes_units=None,
# We plot against pixel coordinates
axes.errorbar(np.arange(len(ydata)), ydata, yerr=yerror, **kwargs)
else:
axes.plot(ydata, **kwargs)
# compute() will break on numpy arrays to catch dask arrays by casting to bool instead
Copy link
Member

Choose a reason for hiding this comment

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

This comment should make more sense to those who aren't dask wonks ;)

if not bool(np.isnan(ydata).all()):
Copy link
Member

Choose a reason for hiding this comment

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

Could something like

Suggested change
if not bool(np.isnan(ydata).all()):
if np.isfinite(ydata).any() and unmasked:

be used instead without causing dask problems? This way both NaN and Inf would be checked. In addition, it would check whether there are valid unmasked data because unmasked would be a bool that would indicate that at least one finite data value is unmasked and default to True. It would be calculated around here.

axes.plot(ydata, **kwargs)

axes.set_ylabel(default_ylabel)

Expand Down
Loading