pyqtgraph / pyqtgraph

Fast data visualization and GUI tools for scientific / engineering applications
https://www.pyqtgraph.org
Other
3.82k stars 1.1k forks source link

ImageView HistogramLUTWidget bug #590

Open feketeimre opened 6 years ago

feketeimre commented 6 years ago

When ImageView is used with an array containing large values the HistogramLUTWidget becomes slightly bugged. The LinearRegionItem cannot be hovered, selected or dragged, only panning and zoom works on the Axis Item. When zoomed in far the axis starts to behave strange too, the ticks get misaligned. The LinearRegionItem hover highlight is off too.

I reproduced the same problems on 32bit Python but it looked fine on 64bit. The issues with zooming still exits on both. Considering this it feels like it has something to do with either numpy or Qt. I have attached an image how it looks for me, there should be a histogram on the picture also, for some reason it wont display either: imageviewbug

You can reproduce the above with the following code:

import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy

plt = pg.image(numpy.random.normal(size=(100,100))*10**50)

if __name__ == '__main__':
    import sys
    if sys.flags.interactive != 1 or not hasattr(pg.QtCore, 'PYQT_VERSION'):
        pg.QtGui.QApplication.exec_()
feketeimre commented 6 years ago

Turns out its a "bug" in Qt. Probably due to loss of precision when mapping with a QTransform having large scale values.

To reproduce a similar problem in Qt, zoom in really far, the red rectangle will disappear suddenly:

from pyqtgraph.Qt import QtGui,QtCore
import sys

class QGraphicsView(QtGui.QGraphicsView):
    def __init__(self, parent=None):
        super(QGraphicsView, self).__init__(parent)

    def wheelEvent(self, ev):
        if   ev.delta()>0: self.scale(1.5, 1.5)
        elif ev.delta()<0: self.scale(0.5, 0.5)

app = QtGui.QApplication(sys.argv)

gw = QGraphicsView()
scene = QtGui.QGraphicsScene()
gw.setScene(scene)

rect = QtGui.QGraphicsRectItem(-10,-10,20,20)
rect.setBrush(QtGui.QBrush(QtGui.QColor(255,0,0,64)))
scene.addItem(rect)

gw.show()
sys.exit(app.exec_())
NilsNemitz commented 3 years ago

This might be related to the Qt coordinate mapping transforms that seem to be unrelaible for extreme values. There is more discussion on that in #1537.

j9ac9k commented 3 years ago

I was hoping #1557 could fix this, but it didn't...there is also some secondary issue with values being too high (error when the exponential value is 20+ no error when the exponential value is 19).

This might be the example I need to replicate potential issues that #1557 is meant to solve.