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

Plot animation throws an error when updating ylim on 1D plots #473

Open
SolarDrew opened this issue Dec 6, 2024 · 1 comment
Open

Plot animation throws an error when updating ylim on 1D plots #473

SolarDrew opened this issue Dec 6, 2024 · 1 comment
Labels
Upstream Issue An issue which is probably in an upstream package of the user tools
Milestone

Comments

@SolarDrew
Copy link
Contributor

SolarDrew commented Dec 6, 2024

Scenario A:

import dkist
from dkist.data.sample import VISP_BKPLX
import matplotlib.pyplot as plt

ds.plot(plot_axes=[None, None, 'x', None])
plt.show()

This plots fine initially but then clicking to cycle through the Stokes axis gives:

Traceback (most recent call last):
  File "/home/drew/mambaforge/envs/dkist-workshop/lib/python3.13/site-packages/matplotlib/cbook.py", line 298, in process
    func(*args, **kwargs)
    ~~~~^^^^^^^^^^^^^^^^^
  File "/home/drew/mambaforge/envs/dkist-workshop/lib/python3.13/site-packages/matplotlib/widgets.py", line 592, in <lambda>
    return self._observers.connect('changed', lambda val: func(val))
                                                          ~~~~^^^^^
  File "/home/drew/mambaforge/envs/dkist-workshop/lib/python3.13/site-packages/mpl_animators/base.py", line 376, in _slider_changed
    self.slider_functions[slider.slider_ind](val, self.im, slider)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/home/drew/mambaforge/envs/dkist-workshop/lib/python3.13/site-packages/mpl_animators/wcs.py", line 231, in update_plot
    self.update_plot_1d(val, artist, slider)
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "/home/drew/mambaforge/envs/dkist-workshop/lib/python3.13/site-packages/mpl_animators/wcs.py", line 280, in update_plot_1d
    self.axes.set_ylim(float(self.data[self.frame_index].min()),
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                       float(self.data[self.frame_index].max()))
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/drew/mambaforge/envs/dkist-workshop/lib/python3.13/site-packages/matplotlib/axes/_base.py", line 3973, in set_ylim
    return self.yaxis._set_lim(bottom, top, emit=emit, auto=auto)
           ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/drew/mambaforge/envs/dkist-workshop/lib/python3.13/site-packages/matplotlib/axis.py", line 1236, in _set_lim
    v0 = self.axes._validate_converted_limits(v0, self.convert_units)
  File "/home/drew/mambaforge/envs/dkist-workshop/lib/python3.13/site-packages/matplotlib/axes/_base.py", line 3660, in _validate_converted_limits
    raise ValueError("Axis limits cannot be NaN or Inf")
ValueError: Axis limits cannot be NaN or Inf

Scenario B:

>>> %timeit ds[0, 0, :, 0].plot() # Sample Stokes I data is available
249 ms ± 9.52 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

>>> %timeit ds[1, 0, :, 0].plot() # This data isn't
1min 13s ± 838 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

Scenario A also takes a while to do anything once it throws the error, so I suspect these things may be linked.

EDIT: On closer inspection Scenario B appears to be unrelated and I've opened a separate issue for it: #477

@SolarDrew SolarDrew moved this from Critical to Usability in User Tools Development Board Dec 6, 2024
@SolarDrew SolarDrew changed the title Using plot() to make a line graph doesn't cope well if there's no data. Plot animation throws an error when updating ylim on 1D plots Dec 10, 2024
@SolarDrew
Copy link
Contributor Author

A similar error occurs when updating a 2D plot if clip_interval is set, due to being unable to calculate vmin and vmax when data is missing.

@SolarDrew SolarDrew modified the milestones: v1.10.0, v1.9.1 Jan 7, 2025
@SolarDrew SolarDrew added the Upstream Issue An issue which is probably in an upstream package of the user tools label Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Upstream Issue An issue which is probably in an upstream package of the user tools
Projects
Status: In progress
Development

No branches or pull requests

1 participant