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

Incorrect y-axis values when SI prefix is disabled #2899

Open
matenestor opened this issue Dec 11, 2023 · 1 comment
Open

Incorrect y-axis values when SI prefix is disabled #2899

matenestor opened this issue Dec 11, 2023 · 1 comment

Comments

@matenestor
Copy link

matenestor commented Dec 11, 2023

Short description

I am plotting some data with values <1e-8 and customizing the plot axes and labels. When I disable SI prefix just before plotting the data (after other things are set, like axes labels and ranges), then the values on the y-axis are incorrect. The scientific notation suffix e-9 or e-10 is not shown.

Code to reproduce

import pyqtgraph as pg

arr = [
    1.20e-09, 1.66e-09, 1.99e-09, 2.10e-09, 1.96e-09,
    1.53e-09, 1.04e-09, 5.70e-10, 2.28e-10, 1.00e-10,
    2.17e-10, 6.35e-10, 1.12e-09, 1.59e-09, 1.95e-09,
    2.10e-09, 2.00e-09, 1.60e-09, 1.12e-09, 6.42e-10,
]

plot = pg.plot([0], [0])

plot.setLabel("bottom", "m/z")
plot.setLabel("left", "I[A]")

# correct
# plot.plotItem.getAxis("left").enableAutoSIPrefix(False)

plot.plotItem.setYRange(min=1e-11, max=25e-10)

# incorrect
plot.plotItem.getAxis("left").enableAutoSIPrefix(False)

plot.plot(x=list(range(len(arr))), y=arr)

# incorrect
# plot.plotItem.getAxis("left").enableAutoSIPrefix(False)

pg.exec()

Expected behavior

The data is plotted with correct value on the y-axis no matter in which order I call set methods on a plot instance.

Real behavior

  1. When data is plotted before the SI prefix is disabled, then the data appear wrong.
  2. When data is plotted after the SI prefix is disabled, then it works as intended, but
  3. When a YRange is set before the SI prefix is disabled, then the data appear wrong again.

Tested environment(s)

  • PyQtGraph version: 0.13.3
  • Qt Python binding: PySide6 6.5.1.1
@sldesnoo-Delft
Copy link

The bug is in AxisItem.updateAutoSIPrefix and enableAutoSIPrefix. updateAutoSIPrefix doesn't check whether the attribute autoSIPrefix is True.
Calling enableAutoSIPrefix(False) after label and range are set still sets the value for autoSIPrefixScale. The method generateDrawSpecs doesn't check value of autoSIPrefix and always uses autoSIPrefixScale.

Proposed solution: set autoSIPrefixScale to 1.0 when autoSIPrefix == False.

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

2 participants