Skip to content

ViewBox quantization limit#2064

Merged
j9ac9k merged 4 commits intopyqtgraph:masterfrom
NilsNemitz:ViewBoxQuantizationLimit
Nov 11, 2021
Merged

ViewBox quantization limit#2064
j9ac9k merged 4 commits intopyqtgraph:masterfrom
NilsNemitz:ViewBoxQuantizationLimit

Conversation

@NilsNemitz
Copy link
Copy Markdown
Contributor

This is meant to address #2056, where the vertical axis collapses when a list of large, constant values is plotted.

The reason for this is that the default 1.0 span of the auto-scaling eventually becomes smaller than the effective (~3e-16) resolution of a double float, and the range calculations break down.

This PR sets the minimum displayed range to 6E-15 of the center value, which makes sure that at least 20 quantization steps are on screen. At this level, the errors become obvious, but the plot remains visible, and the axis manages to calculate ticks and labels.

For values < 1.6e+14, the behavior should be unchanged, except that there is now a hard lower limit on the plot range: It is no longer possible to deliberately collapse the axis range to zero. However, I could not come up with a good reason to do so.

Here is some code to play around with, based on the report in #2056:

from pyqtgraph.Qt import QtGui
import pyqtgraph as pg

app = pg.mkQApp()
mw = QtGui.QMainWindow()
cw = QtGui.QWidget()
mw.setCentralWidget(cw)
l = QtGui.QVBoxLayout()
cw.setLayout(l)

pw = pg.PlotWidget(name='Plot1') 
l.addWidget(pw)
mw.show()
constant = 8e15 # now keeps working until other things break for >8e130 
p1 = pw.plot(y=[constant,constant])

# uncomment this to see quantization errors:
# p1 = pw.plot(y=[constant,constant+1,constant+2])

# uncomment this to see hard limit on axis range:
# pw.setYRange(constant-0, constant+0, padding=0)

if __name__ == '__main__':
    pg.exec()

Closes #2056, I hope.

@NilsNemitz NilsNemitz changed the title View box quantization limit ViewBox quantization limit Nov 8, 2021
quantization_limit = (mn+mx) * 1.5e-15 # +/-10 discrete steps of double resolution
if mx-mn < 2*quantization_limit:
mn -= quantization_limit
mx += quantization_limit
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks good to me. Thanks. I just have a very minor point: regarding the comment approx. eps, stands for approximated double resolution ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, numpy seems to call it that. I think C spells it out as epsilon, typically.
https://numpy.org/doc/stable/reference/generated/numpy.finfo.html
According to that page: eps = 2**-52, approximately 2.22e-16.
But there is no real benefit to being ultra-accurate here; I am just trying to explain the magic cutoff value.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Nov 11, 2021

thanks for the PR @NilsNemitz, merging!

@j9ac9k j9ac9k merged commit 5d7216e into pyqtgraph:master Nov 11, 2021
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.

Plot does not do show constant values for value above 4.5e15 (roughly)

3 participants