summaryrefslogtreecommitdiff
path: root/silx/gui/plot
diff options
context:
space:
mode:
Diffstat (limited to 'silx/gui/plot')
-rwxr-xr-xsilx/gui/plot/PlotWidget.py3
-rw-r--r--silx/gui/plot/ProfileMainWindow.py3
-rw-r--r--silx/gui/plot/StatsWidget.py33
-rwxr-xr-xsilx/gui/plot/backends/BackendMatplotlib.py23
-rw-r--r--silx/gui/plot/items/shape.py2
-rw-r--r--silx/gui/plot/tools/profile/_BaseProfileToolBar.py2
6 files changed, 49 insertions, 17 deletions
diff --git a/silx/gui/plot/PlotWidget.py b/silx/gui/plot/PlotWidget.py
index 49e444a..e47249e 100755
--- a/silx/gui/plot/PlotWidget.py
+++ b/silx/gui/plot/PlotWidget.py
@@ -624,8 +624,7 @@ class PlotWidget(qt.QMainWindow):
# Add item to plot
self._content[key] = item
item._setPlot(self)
- if item.isVisible():
- self._itemRequiresUpdate(item)
+ self._itemRequiresUpdate(item)
if isinstance(item, items.DATA_ITEMS):
self._invalidateDataRange() # TODO handle this automatically
diff --git a/silx/gui/plot/ProfileMainWindow.py b/silx/gui/plot/ProfileMainWindow.py
index 39830d8..aaedd1c 100644
--- a/silx/gui/plot/ProfileMainWindow.py
+++ b/silx/gui/plot/ProfileMainWindow.py
@@ -1,7 +1,7 @@
# coding: utf-8
# /*##########################################################################
#
-# Copyright (c) 2017-2018 European Synchrotron Radiation Facility
+# Copyright (c) 2017-2020 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -85,6 +85,7 @@ class ProfileMainWindow(qt.QMainWindow):
self._plot2D.setParent(None) # necessary to avoid widget destruction
if self._plot1D is None:
self._plot1D = Plot1D(backend=self._backend)
+ self._plot1D.setDataMargins(yMinMargin=0.1, yMaxMargin=0.1)
self._plot1D.setGraphYLabel('Profile')
self._plot1D.setGraphXLabel('')
self.setCentralWidget(self._plot1D)
diff --git a/silx/gui/plot/StatsWidget.py b/silx/gui/plot/StatsWidget.py
index 80bc05d..52b7e5c 100644
--- a/silx/gui/plot/StatsWidget.py
+++ b/silx/gui/plot/StatsWidget.py
@@ -424,7 +424,7 @@ class _StatsWidgetBase(object):
if self._displayOnlyActItem:
connections.append(
- (self._plotWrapper.sigCurrentChanged, self._updateItemObserve))
+ (self._plotWrapper.sigCurrentChanged, self._updateCurrentItem))
else:
connections += [
(self._plotWrapper.sigItemAdded, self._addItem),
@@ -441,6 +441,11 @@ class _StatsWidgetBase(object):
"""Reload table depending on mode"""
raise NotImplementedError('Base class')
+ def _updateCurrentItem(self, *args):
+ """specific callback for the sigCurrentChanged and with the
+ _displayOnlyActItem option."""
+ raise NotImplementedError('Base class')
+
def _updateStats(self, item):
"""Update displayed information for given plot item
@@ -643,8 +648,6 @@ class StatsTable(_StatsWidgetBase, TableWidget):
def _updateItemObserve(self, *args):
"""Reload table depending on mode"""
- if self.getUpdateMode() is UpdateMode.MANUAL:
- return
self._removeAllItems()
# Get selected or all items from the plot
@@ -657,6 +660,27 @@ class StatsTable(_StatsWidgetBase, TableWidget):
for item in items:
self._addItem(item)
+ def _updateCurrentItem(self, *args):
+ """specific callback for the sigCurrentChanged and with the
+ _displayOnlyActItem option.
+
+ Behavior: create the tableItems if does not exists.
+ If exists, update it only when we are in 'auto' mode"""
+ if self.getUpdateMode() is UpdateMode.MANUAL:
+ # when sigCurrentChanged is giving the current item
+ if len(args) > 0 and isinstance(args[0], (plotitems.Curve, plotitems.Histogram, plotitems.ImageData, plotitems.Scatter)):
+ item = args[0]
+ tableItems = self._itemToTableItems(item)
+ # if the table does not exists yet
+ if len(tableItems) == 0:
+ self._updateItemObserve()
+ else:
+ # in this case no current item
+ self._updateItemObserve(args)
+ else:
+ # auto mode
+ self._updateItemObserve(args)
+
def _plotCurrentChanged(self, current):
"""Handle change of current item and update selection in table
@@ -1392,6 +1416,9 @@ class _BaseLineStatsWidget(_StatsWidgetBase, qt.QWidget):
_item = items[0] if len(items) is 1 else None
self._setItem(_item)
+ def _updateCurrentItem(self):
+ self._updateItemObserve()
+
def _createLayout(self):
"""create an instance of the main QLayout"""
raise NotImplementedError('Base class')
diff --git a/silx/gui/plot/backends/BackendMatplotlib.py b/silx/gui/plot/backends/BackendMatplotlib.py
index 075f6aa..2336494 100755
--- a/silx/gui/plot/backends/BackendMatplotlib.py
+++ b/silx/gui/plot/backends/BackendMatplotlib.py
@@ -1094,13 +1094,16 @@ class BackendMatplotlib(BackendBase.BackendBase):
# Data <-> Pixel coordinates conversion
- def _mplQtYAxisCoordConversion(self, y):
+ def _mplQtYAxisCoordConversion(self, y, asint=True):
"""Qt origin (top) to/from matplotlib origin (bottom) conversion.
+ :param y:
+ :param bool asint: True to cast to int, False to keep as float
+
:rtype: float
"""
- height = self.fig.get_window_extent().height
- return height - y
+ value = self.fig.get_window_extent().height - y
+ return int(value) if asint else value
def dataToPixel(self, x, y, axis):
ax = self.ax2 if axis == "right" else self.ax
@@ -1109,7 +1112,7 @@ class BackendMatplotlib(BackendBase.BackendBase):
xPixel, yPixel = pixels.T
# Convert from matplotlib origin (bottom) to Qt origin (top)
- yPixel = self._mplQtYAxisCoordConversion(yPixel)
+ yPixel = self._mplQtYAxisCoordConversion(yPixel, asint=False)
return xPixel, yPixel
@@ -1117,7 +1120,7 @@ class BackendMatplotlib(BackendBase.BackendBase):
ax = self.ax2 if axis == "right" else self.ax
# Convert from Qt origin (top) to matplotlib origin (bottom)
- y = self._mplQtYAxisCoordConversion(y)
+ y = self._mplQtYAxisCoordConversion(y, asint=False)
inv = ax.transData.inverted()
x, y = inv.transform_point((x, y))
@@ -1126,10 +1129,10 @@ class BackendMatplotlib(BackendBase.BackendBase):
def getPlotBoundsInPixels(self):
bbox = self.ax.get_window_extent()
# Warning this is not returning int...
- return (bbox.xmin,
- self._mplQtYAxisCoordConversion(bbox.ymax),
- bbox.width,
- bbox.height)
+ return (int(bbox.xmin),
+ self._mplQtYAxisCoordConversion(bbox.ymax, asint=True),
+ int(bbox.width),
+ int(bbox.height))
def setAxesDisplayed(self, displayed):
"""Display or not the axes.
@@ -1263,7 +1266,7 @@ class BackendMatplotlibQt(FigureCanvasQTAgg, BackendMatplotlib):
def _onMouseMove(self, event):
if self._graphCursor:
lineh, linev = self._graphCursor
- if event.inaxes != self.ax and lineh.get_visible():
+ if event.inaxes not in (self.ax, self.ax2) and lineh.get_visible():
lineh.set_visible(False)
linev.set_visible(False)
self._plot._setDirtyPlot(overlayOnly=True)
diff --git a/silx/gui/plot/items/shape.py b/silx/gui/plot/items/shape.py
index e6dc529..8176be1 100644
--- a/silx/gui/plot/items/shape.py
+++ b/silx/gui/plot/items/shape.py
@@ -197,6 +197,8 @@ class BoundingRect(Item, YAxisMixIn):
self._updated(ItemChangedType.DATA)
def _getBounds(self):
+ if self.__bounds is None:
+ return None
plot = self.getPlot()
if plot is not None:
xPositive = plot.getXAxis()._isLogarithmic()
diff --git a/silx/gui/plot/tools/profile/_BaseProfileToolBar.py b/silx/gui/plot/tools/profile/_BaseProfileToolBar.py
index ced81da..75bb4c6 100644
--- a/silx/gui/plot/tools/profile/_BaseProfileToolBar.py
+++ b/silx/gui/plot/tools/profile/_BaseProfileToolBar.py
@@ -231,7 +231,7 @@ class _BaseProfileToolBar(qt.QToolBar):
profilePlot.addCurve(
xProfile, values, legend='Profile', color=self._color)
- self._showDefaultProfileWindow()
+ self._showDefaultProfileWindow()
def _showDefaultProfileWindow(self):
"""If profile window was created by this toolbar,