Skip to content

Commit

Permalink
Merge pull request #1056 from vasole/m1d
Browse files Browse the repository at this point in the history
[GUI] Correct saving 1D data via matplotlib
  • Loading branch information
vasole authored Dec 5, 2023
2 parents d89fccf + 6a23ad6 commit 6a4cbc8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
18 changes: 6 additions & 12 deletions PyMca5/PyMcaGui/pymca/QPyMcaMatplotlibSave1D.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#/*##########################################################################
# Copyright (C) 2004-2022 European Synchrotron Radiation Facility
# Copyright (C) 2004-2023 European Synchrotron Radiation Facility
#
# This file is part of the PyMca X-ray Fluorescence Toolkit developed at
# the ESRF.
Expand Down Expand Up @@ -39,16 +39,8 @@

from matplotlib import __version__ as matplotlib_version
from matplotlib.font_manager import FontProperties
if qt.BINDING in ["PyQt5", "PySide2"]:
import matplotlib
matplotlib.rcParams['backend']='Qt5Agg'
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
elif qt.BINDING in ["PyQt6", "PySide6"]:
import matplotlib
matplotlib.rcParams['backend']='Qt5Agg'
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
else:
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
import matplotlib
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -223,7 +215,7 @@ def _mySlot(self, ddict):
class ComboBoxItem(qt.QComboBox):
sigComboBoxItemSignal = qt.pyqtSignal(object)
def __init__(self, parent, row, col, options=[1,2,3]):
qt.QCheckBox.__init__(self, parent)
qt.QComboBox.__init__(self, parent)
self.__row = row
self.__col = col
for option in options:
Expand Down Expand Up @@ -490,6 +482,8 @@ def addDataToPlot(self, x, y, legend = None,
linestyle = None,
marker=None,
alias = None,**kw):
x = numpy.array(x, copy=False)
y = numpy.array(y, copy=False)
if self.limitsSet is not None:
n = self._filterData(x, y)
if not len(n):
Expand Down
20 changes: 20 additions & 0 deletions PyMca5/tests/WidgetsInstantiationTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,25 @@ def testShow(self):
widget.show()
self.qapp.processEvents()

class TestQPyMcaMatplotlibSave1D(TestCaseQt):
def setUp(self):
super(TestQPyMcaMatplotlibSave1D, self).setUp()

def testShow(self):
from PyMca5.PyMcaGui.pymca import QPyMcaMatplotlibSave1D
widget = QPyMcaMatplotlibSave1D.QPyMcaMatplotlibSaveDialog()
w = widget.plot
w.setLimits(0, 3, 0, 9)
w.addDataToPlot([0, 1, 2, 3], [0, 1, 4, 9], legend="1")
widget.setXLabel('Channel')
widget.setYLabel('Counts')
w.plotLegends()
widget.show()
self.qapp.processEvents()
from PyMca5.PyMcaGui.plotting import PyMcaPrintPreview
PyMcaPrintPreview.resetSingletonPrintPreview()


class TestScanWindow(TestCaseQt):
def setUp(self):
super(TestScanWindow, self).setUp()
Expand Down Expand Up @@ -254,6 +273,7 @@ def runTest(self):
TestXASNormalizationWindow,
TestMaskImageWidget,
TestScanWindow,
TestQPyMcaMatplotlibSave1D,
TestMcaCalWidget,
TestMcaWindow,
TestMaterialEditor,
Expand Down

0 comments on commit 6a4cbc8

Please sign in to comment.