diff --git a/qt/applications/workbench/workbench/plotting/propertiesdialog.py b/qt/applications/workbench/workbench/plotting/propertiesdialog.py index a39b5c45d7380e779aa771f6fabb9399d411daaa..c720dd1124ba0384a9b0a58e4aa46b98a9e0fecd 100644 --- a/qt/applications/workbench/workbench/plotting/propertiesdialog.py +++ b/qt/applications/workbench/workbench/plotting/propertiesdialog.py @@ -20,7 +20,7 @@ from matplotlib.colors import LogNorm, Normalize from qtpy.QtGui import QDoubleValidator, QIcon from qtpy.QtWidgets import QDialog, QWidget -SYMLOG_LIN_THRESHOLD = 0.01 +TREAT_LOG_NEGATIVE_VALUES = 'clip' class PropertiesEditorBase(QDialog): @@ -94,7 +94,6 @@ class LabelEditor(PropertiesEditorBase): class AxisEditorModel(object): - min = None max = None log = None @@ -122,9 +121,10 @@ class AxisEditor(PropertiesEditorBase): self.axes = axes self.axis_id = axis_id + self.lim_getter = getattr(axes, 'get_{}lim'.format(axis_id)) self.lim_setter = getattr(axes, 'set_{}lim'.format(axis_id)) self.scale_setter = getattr(axes, 'set_{}scale'.format(axis_id)) - self.linthresholdkw = 'linthres' + axis_id + self.nonposkw = 'nonpos' + axis_id # Grid has no direct accessor from the axes self.axis = axes.xaxis if axis_id == 'x' else axes.yaxis @@ -133,8 +133,8 @@ class AxisEditor(PropertiesEditorBase): self._memento = memento memento.min, memento.max = getattr(self.axes, 'get_{}lim'.format(self.axis_id))() memento.log = getattr(self.axes, 'get_{}scale'.format(self.axis_id))() != 'linear' - ticks = self.axis.majorTicks[0] - if hasattr(ticks,"get_visible"): + ticks = self.axis.majorTicks[0] + if hasattr(ticks, "get_visible"): memento.grid = ticks.get_visible() else: memento.grid = ticks.gridOn @@ -147,11 +147,15 @@ class AxisEditor(PropertiesEditorBase): axes = self.axes self.limit_min, self.limit_max = float(self.ui.editor_min.text()), float(self.ui.editor_max.text()) - self.lim_setter(self.limit_min, self.limit_max) + if self.ui.logBox.isChecked(): - self.scale_setter('symlog', **{self.linthresholdkw: SYMLOG_LIN_THRESHOLD}) + self.scale_setter('log', **{self.nonposkw: TREAT_LOG_NEGATIVE_VALUES}) + self.limit_min, self.limit_max = self._check_log_limits(self.limit_min, self.limit_max) else: self.scale_setter('linear') + + self.lim_setter(self.limit_min, self.limit_max) + axes.grid(self.ui.gridBox.isChecked(), axis=self.axis_id) def error_occurred(self, exc): @@ -167,6 +171,16 @@ class AxisEditor(PropertiesEditorBase): self.ui.logBox.setChecked(model.log) self.ui.gridBox.setChecked(model.grid) + def _check_log_limits(self, editor_min, editor_max): + # Check that the limits from the editor are sensible for a log graph + # As these limits are not necessarily in numeric order we have to check both + lim_min, lim_max = self.lim_getter() + if editor_min <= 0: + editor_min = lim_min + if editor_max <= 0: + editor_max = lim_max + return editor_min, editor_max + class XAxisEditor(AxisEditor):