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: Enabling keep data aspect ratio and an axis with log scale makes zoom raise an exception #4210

Open
t20100 opened this issue Feb 3, 2025 · 0 comments

Comments

@t20100
Copy link
Member

t20100 commented Feb 3, 2025

Tested with python3.12, matplotlib 3.9.4 and 3.10.

To reproduce:

from silx import sx
w = sx.plot((1, 2, 3))
w.setKeepDataAspectRatio(True)
w.getYAxis().setScale("log")

and zoom with the mouse wheel.

I expected keep aspect ratio to be disabled when an axis is in log scale, apparently not.

Exception:
python3.12/site-packages/matplotlib/scale.py:255: RuntimeWarning: overflow encountered in power
  return np.power(self.base, values)
Traceback (most recent call last):
  File "python3.12/site-packages/matplotlib/cbook.py", line 298, in process
    func(*args, **kwargs)
  File "silx/gui/plot/backends/BackendMatplotlib.py", line 1569, in _onMouseWheel
    self._plot.onMouseWheel(int(x), int(y), event.step)
  File "silx/gui/plot/PlotWidget.py", line 3650, in onMouseWheel
    self._eventHandler.handleEvent("wheel", xPixel, yPixel, angleInDegrees)
  File "silx/gui/plot/PlotInteraction.py", line 1861, in handleEvent
    self._onWheel(*args, **kwargs)
  File "silx/gui/plot/PlotInteraction.py", line 1885, in _onWheel
    applyZoomToPlot(plotWidget, scale, (x, y), enabledAxes)
  File "silx/src/silx/gui/plot/_utils/panzoom.py", line 179, in applyZoomToPlot
    plot.setLimits(xMin, xMax, yMin, yMax, y2Min, y2Max)
  File "silx/src/silx/gui/plot/PlotWidget.py", line 2745, in setLimits
    self._notifyLimitsChanged()
  File "silx/src/silx/gui/plot/PlotWidget.py", line 2619, in _notifyLimitsChanged
    xRange = self._xAxis.getLimits()
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "silx/src/silx/gui/plot/items/axis.py", line 122, in getLimits
    return self._internalGetLimits()
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "silx/src/silx/gui/plot/items/axis.py", line 414, in _internalGetLimits
    return self._getBackend().getGraphXLimits()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "silx/src/silx/gui/plot/backends/BackendMatplotlib.py", line 1210, in getGraphXLimits
    self.ax.apply_aspect()
  File "python3.12/site-packages/matplotlib/axes/_base.py", line 2025, in apply_aspect
    self.set_ybound(y_trf.inverted().transform([y0, y1]))
  File "python3.12/site-packages/matplotlib/axes/_base.py", line 3871, in set_ybound
    self.set_ylim(sorted((lower, upper),
  File "python3.12/site-packages/matplotlib/axes/_base.py", line 3973, in set_ylim
    return self.yaxis._set_lim(bottom, top, emit=emit, auto=auto)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "python3.12/site-packages/matplotlib/axis.py", line 1237, in _set_lim
    v1 = self.axes._validate_converted_limits(v1, self.convert_units)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "python3.12/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
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

No branches or pull requests

1 participant