weird bug for log-scaling fixed; fixes T248

This commit is contained in:
Dominik Demuth 2022-12-30 14:06:25 +01:00
parent b1e54c8432
commit bf437ef8a7
3 changed files with 23 additions and 7 deletions

View File

@ -25,6 +25,9 @@ class QShift(QtWidgets.QDialog, Ui_shift_dialog):
self.data = {} self.data = {}
self._colors = cycle(Tab10) self._colors = cycle(Tab10)
self.graphicsView.plotItem.ctrl.logXCheck.blockSignals(True)
self.graphicsView.plotItem.ctrl.logYCheck.blockSignals(True)
delegate = SpinBoxDelegate() delegate = SpinBoxDelegate()
delegate.valueChanged.connect(self.shift) delegate.valueChanged.connect(self.shift)
self.shift_table.setItemDelegate(delegate) self.shift_table.setItemDelegate(delegate)
@ -40,10 +43,10 @@ class QShift(QtWidgets.QDialog, Ui_shift_dialog):
def add_item(self, idx, name, x, y): def add_item(self, idx, name, x, y):
color = mkColor(next(self._colors).rgb()) color = mkColor(next(self._colors).rgb())
if np.iscomplexobj(y): if np.iscomplexobj(y):
pl = [PlotItem(x, y.real, name=name, pen=mkPen(color=color)), pl = [PlotItem(x=x, y=y.real, name=name, pen=mkPen(color=color)),
PlotItem(x, y.imag, name=name, pen=mkPen(color=color))] PlotItem(x=x, y=y.imag, name=name, pen=mkPen(color=color))]
else: else:
pl = [PlotItem(x, y, name=name, pen=mkPen(color=color))] pl = [PlotItem(x=x, y=y, name=name, symbol='t', pen=mkPen(color=color))]
self.data[idx] = (pl, x, y) self.data[idx] = (pl, x, y)
@ -123,10 +126,18 @@ class QShift(QtWidgets.QDialog, Ui_shift_dialog):
def set_log(self, state: int): def set_log(self, state: int):
if self.sender() == self.xlog_checkbox: if self.sender() == self.xlog_checkbox:
log_state = self.graphicsView.plotItem.ctrl.logXCheck log_state = self.graphicsView.plotItem.ctrl.logXCheck
func = self.graphicsView.setXRange
else: else:
log_state = self.graphicsView.plotItem.ctrl.logYCheck log_state = self.graphicsView.plotItem.ctrl.logYCheck
func = self.graphicsView.setYRange
log_state.setCheckState(state) log_state.setCheckState(state)
self.graphicsView.plotItem.updateLogMode() self.graphicsView.plotItem.updateLogMode()
# For some combinations of Python, pyqt, and pyqtgraph, updateLogMode does not update
# view range to log values and logTickValues generates LOTS of ticks, which freezes everything.
# -> Call setRange to interrupt the loop.
func(0, 1)
self.graphicsView.enableAutoRange()
def on_overwrite_checkbox_stateChanged(self, state: int): def on_overwrite_checkbox_stateChanged(self, state: int):
self.data_newgraph.setVisible(state != QtCore.Qt.Checked) self.data_newgraph.setVisible(state != QtCore.Qt.Checked)

View File

@ -419,7 +419,7 @@ class QGraphWindow(QtWidgets.QGraphicsView, Ui_GraphWindow):
self.plotItem.updateLogMode() self.plotItem.updateLogMode()
self.set_range(x=r[0], y=r[1]) self.plotItem.enableAutoRange()
def enable_picking(self, enabled: bool): def enable_picking(self, enabled: bool):
if enabled: if enabled:

View File

@ -179,8 +179,12 @@ class PlotItem(PlotDataItem):
self.opts['linecolor'] = c.red(), c.green(), c.blue() self.opts['linecolor'] = c.red(), c.green(), c.blue()
if self.symbol != SymbolStyle.No: if self.symbol != SymbolStyle.No:
c = self.opts['symbolBrush'].color() brush = self.opts['symbolBrush']
self.opts['symbolcolor'] = c.red(), c.green(), c.blue() if isinstance(brush, tuple):
self.opts['symbolcolor'] = brush
else:
c = brush.color()
self.opts['symbolcolor'] = c.red(), c.green(), c.blue()
def __getitem__(self, item): def __getitem__(self, item):
return self.opts.get(item, None) return self.opts.get(item, None)
@ -229,7 +233,7 @@ class PlotItem(PlotDataItem):
else: else:
return lc return lc
def updateItems(self): def updateItems(self, styleUpdate=True):
""" """
We override this function so that curves with nan/inf values can be displayed. We override this function so that curves with nan/inf values can be displayed.
Newer versions close this bug differently (https://github.com/pyqtgraph/pyqtgraph/pull/1058) Newer versions close this bug differently (https://github.com/pyqtgraph/pyqtgraph/pull/1058)
@ -261,6 +265,7 @@ class PlotItem(PlotDataItem):
# remove all bad values # remove all bad values
x = x[is_finite] x = x[is_finite]
y = y[is_finite] y = y[is_finite]
curveArgs['connect'] = 'all'
self.curve.setData(x=x, y=y, **curveArgs) self.curve.setData(x=x, y=y, **curveArgs)
self.curve.show() self.curve.show()
else: else: