本文整理汇总了Python中silx.gui.plot.PlotWidget类的典型用法代码示例。如果您正苦于以下问题:Python PlotWidget类的具体用法?Python PlotWidget怎么用?Python PlotWidget使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PlotWidget类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, *var, **kw):
PlotWidget.__init__(self, *var, **kw)
# No context menu by default, execute zoomBack on right click
if "backend" in kw:
setBackend = kw["backend"]
else:
setBackend = None
_logger.info("SilxBackend called with backend = %s" % setBackend)
plotArea = self.getWidgetHandle()
plotArea.setContextMenuPolicy(qt.Qt.CustomContextMenu)
plotArea.customContextMenuRequested.connect(self._zoomBack)
示例2: __init__
def __init__(self, parent=None):
super(MaskScatterWidget, self).__init__(parent=parent)
self._activeScatterLegend = "active scatter"
self._bgImageLegend = "background image"
# widgets
centralWidget = qt.QWidget(self)
self._plot = PlotWidget(parent=centralWidget)
self._maskToolsWidget = ScatterMaskToolsWidget.ScatterMaskToolsWidget(
plot=self._plot, parent=centralWidget)
self._alphaSlider = NamedScatterAlphaSlider(parent=self, plot=self._plot)
self._alphaSlider.setOrientation(qt.Qt.Horizontal)
self._alphaSlider.setToolTip("Adjust scatter opacity")
# layout
layout = qt.QVBoxLayout(centralWidget)
layout.addWidget(self._plot)
layout.addWidget(self._alphaSlider)
layout.addWidget(self._maskToolsWidget)
centralWidget.setLayout(layout)
self.setCentralWidget(centralWidget)
示例3: __init__
def __init__(self, parent = None, backend=None, selection=False, aspect=True,
colormap=False,
imageicons=False, standalonesave=True, standalonezoom=True,
profileselection=False, polygon=False):
qt.QWidget.__init__(self, parent)
self.mainLayout = qt.QVBoxLayout(self)
self.mainLayout.setContentsMargins(0, 0, 0, 0)
self.mainLayout.setSpacing(0)
self._keepDataAspectRatioFlag = False
self.graph = PlotWidget(parent=self, backend=backend)
self.graph.setGraphXLabel("Column")
self.graph.setGraphYLabel("Row")
self.graph.setYAxisAutoScale(True)
self.graph.setXAxisAutoScale(True)
plotArea = self.graph.getWidgetHandle()
plotArea.setContextMenuPolicy(qt.Qt.CustomContextMenu)
plotArea.customContextMenuRequested.connect(self._zoomBack)
self._buildToolBar(selection, colormap, imageicons,
standalonesave,
standalonezoom=standalonezoom,
profileselection=profileselection,
aspect=aspect,
polygon=polygon)
if profileselection:
if len(self._pickerSelectionButtons):
self.graph.sigPlotSignal.connect(\
self._graphPolygonSignalReceived)
self._pickerSelectionWidthValue.valueChanged[int].connect( \
self.setPickerSelectionWith)
self.saveDirectory = os.getcwd()
self.mainLayout.addWidget(self.graph)
示例4: addCurve
def addCurve(self, *var, **kw):
if "replot" in kw:
if kw["replot"]:
kw["resetzoom"] = True
del kw["replot"]
result = PlotWidget.addCurve(self, *var, **kw)
allCurves = self.getAllCurves(just_legend=True)
if len(allCurves) == 1:
self.setActiveCurve(allCurves[0])
return result
示例5: __init__
def __init__(self, parent=None):
qt.QWidget.__init__(self, parent)
self.setWindowTitle("Strip and SNIP Configuration Window")
self.mainLayout = qt.QVBoxLayout(self)
self.mainLayout.setContentsMargins(0, 0, 0, 0)
self.mainLayout.setSpacing(2)
self.parametersWidget = BackgroundParamWidget(self)
self.graphWidget = PlotWidget(parent=self)
self.mainLayout.addWidget(self.parametersWidget)
self.mainLayout.addWidget(self.graphWidget)
self._x = None
self._y = None
self.parametersWidget.sigBackgroundParamWidgetSignal.connect(self._slot)
示例6: setUp
def setUp(self):
super(TestNamedImageAlphaSlider, self).setUp()
self.plot = PlotWidget()
self.aslider = AlphaSlider.NamedImageAlphaSlider(plot=self.plot)
self.aslider.setOrientation(qt.Qt.Horizontal)
toolbar = qt.QToolBar("plot", self.plot)
toolbar.addWidget(self.aslider)
self.plot.addToolBar(toolbar)
self.plot.show()
self.qWaitForWindowExposed(self.plot)
self.mouseMove(self.plot) # Move to center
self.qapp.processEvents()
示例7: addImage
def addImage(self, *var, **kw):
if "replot" in kw:
del kw["replot"]
if "xScale" in kw:
xScale = kw["xScale"]
del kw["xScale"]
if "yScale" in kw:
yScale = kw["yScale"]
del kw["yScale"]
if xScale is not None or yScale is not None:
origin = kw.get("origin", None)
scale = kw.get("scale", None)
if origin is None and scale is None:
kw["origin"] = xScale[0], yScale[0]
kw["scale"] = xScale[1], yScale[1]
return PlotWidget.addImage(self, *var, **kw)
示例8: _PlotWidgetTest
class _PlotWidgetTest(TestCaseQt):
"""Base class for tests of PlotWidget, not a TestCase in itself.
plot attribute is the PlotWidget created for the test.
"""
def setUp(self):
super(_PlotWidgetTest, self).setUp()
self.plot = PlotWidget()
self.plot.show()
self.qWaitForWindowExposed(self.plot)
def tearDown(self):
self.qapp.processEvents()
self.plot.setAttribute(qt.Qt.WA_DeleteOnClose)
self.plot.close()
del self.plot
super(_PlotWidgetTest, self).tearDown()
示例9: setUp
def setUp(self):
self.plot = PlotWidget(backend='none')
self.saveAction = SaveAction(plot=self.plot)
self.tempdir = tempfile.mkdtemp()
self.out_fname = os.path.join(self.tempdir, "out.dat")
示例10: setUp
def setUp(self):
self.plot = PlotWidget()
示例11: TestSaveActionSaveCurvesAsSpec
class TestSaveActionSaveCurvesAsSpec(unittest.TestCase):
def setUp(self):
self.plot = PlotWidget(backend='none')
self.saveAction = SaveAction(plot=self.plot)
self.tempdir = tempfile.mkdtemp()
self.out_fname = os.path.join(self.tempdir, "out.dat")
def tearDown(self):
os.unlink(self.out_fname)
os.rmdir(self.tempdir)
def testSaveMultipleCurvesAsSpec(self):
"""Test that labels are properly used."""
self.plot.setGraphXLabel("graph x label")
self.plot.setGraphYLabel("graph y label")
self.plot.addCurve([0, 1], [1, 2], "curve with labels",
xlabel="curve0 X", ylabel="curve0 Y")
self.plot.addCurve([-1, 3], [-6, 2], "curve with X label",
xlabel="curve1 X")
self.plot.addCurve([-2, 0], [8, 12], "curve with Y label",
ylabel="curve2 Y")
self.plot.addCurve([3, 1], [7, 6], "curve with no labels")
self.saveAction._saveCurves(self.plot,
self.out_fname,
SaveAction.DEFAULT_ALL_CURVES_FILTERS[0]) # "All curves as SpecFile (*.dat)"
with open(self.out_fname, "rb") as f:
file_content = f.read()
if hasattr(file_content, "decode"):
file_content = file_content.decode()
# case with all curve labels specified
self.assertIn("#S 1 curve0 Y", file_content)
self.assertIn("#L curve0 X curve0 Y", file_content)
# graph X&Y labels are used when no curve label is specified
self.assertIn("#S 2 graph y label", file_content)
self.assertIn("#L curve1 X graph y label", file_content)
self.assertIn("#S 3 curve2 Y", file_content)
self.assertIn("#L graph x label curve2 Y", file_content)
self.assertIn("#S 4 graph y label", file_content)
self.assertIn("#L graph x label graph y label", file_content)
示例12: __init__
def __init__(self, parent=None):
qt.QMainWindow.__init__(self, parent=parent)
if parent is not None:
# behave as a widget
self.setWindowFlags(qt.Qt.Widget)
else:
self.setWindowTitle("PyMca - Image Selection Tool")
centralWidget = qt.QWidget(self)
layout = qt.QVBoxLayout(centralWidget)
centralWidget.setLayout(layout)
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(0)
# Plot
self.plot = PlotWidget(parent=centralWidget)
self.plot.setWindowFlags(qt.Qt.Widget)
self.plot.setDefaultColormap({'name': 'temperature',
'normalization': 'linear',
'autoscale': True,
'vmin': 0.,
'vmax': 1.})
layout.addWidget(self.plot)
# Mask Widget
self._maskToolsDockWidget = None
# Image selection slider
self.slider = qt.QSlider(self.centralWidget())
self.slider.setOrientation(qt.Qt.Horizontal)
self.slider.setMinimum(0)
self.slider.setMaximum(0)
layout.addWidget(self.slider)
self.slider.valueChanged[int].connect(self.showImage)
# ADD/REMOVE/REPLACE IMAGE buttons
buttonBox = qt.QWidget(self)
buttonBoxLayout = qt.QHBoxLayout(buttonBox)
buttonBoxLayout.setContentsMargins(0, 0, 0, 0)
buttonBoxLayout.setSpacing(0)
self.addImageButton = qt.QPushButton(buttonBox)
icon = qt.QIcon(qt.QPixmap(IconDict["rgb16"]))
self.addImageButton.setIcon(icon)
self.addImageButton.setText("ADD IMAGE")
self.addImageButton.setToolTip("Add image to RGB correlator")
buttonBoxLayout.addWidget(self.addImageButton)
self.removeImageButton = qt.QPushButton(buttonBox)
self.removeImageButton.setIcon(icon)
self.removeImageButton.setText("REMOVE IMAGE")
self.removeImageButton.setToolTip("Remove image from RGB correlator")
buttonBoxLayout.addWidget(self.removeImageButton)
self.replaceImageButton = qt.QPushButton(buttonBox)
self.replaceImageButton.setIcon(icon)
self.replaceImageButton.setText("REPLACE IMAGE")
self.replaceImageButton.setToolTip(
"Replace all images in RGB correlator with this one")
buttonBoxLayout.addWidget(self.replaceImageButton)
self.addImageButton.clicked.connect(self._addImageClicked)
self.removeImageButton.clicked.connect(self._removeImageClicked)
self.replaceImageButton.clicked.connect(self._replaceImageClicked)
layout.addWidget(buttonBox)
# median filter widget
self._medianParameters = {'row_width': 1,
'column_width': 1,
'conditional': 0}
self._medianParametersWidget = MedianParameters(self,
use_conditional=True)
self._medianParametersWidget.widthSpin.setValue(1)
self._medianParametersWidget.widthSpin.valueChanged[int].connect(
self._setMedianKernelWidth)
self._medianParametersWidget.conditionalSpin.valueChanged[int].connect(
self._setMedianConditionalFlag)
layout.addWidget(self._medianParametersWidget)
# motor positions (hidden by default)
self.motorPositionsWidget = MotorInfoWindow.MotorInfoDialog(self,
[""],
[{}])
self.motorPositionsWidget.setMaximumHeight(100)
self.plot.sigPlotSignal.connect(self._updateMotors)
self.motorPositionsWidget.hide()
self._motors_first_update = True
layout.addWidget(self.motorPositionsWidget)
self.setCentralWidget(centralWidget)
# Init actions
self.group = qt.QActionGroup(self)
self.group.setExclusive(False)
self.resetZoomAction = self.group.addAction(
PlotActions.ResetZoomAction(plot=self.plot, parent=self))
self.addAction(self.resetZoomAction)
#.........这里部分代码省略.........
示例13: TestLimitConstaints
class TestLimitConstaints(unittest.TestCase):
"""Tests setLimitConstaints class"""
def setUp(self):
self.plot = PlotWidget()
def tearDown(self):
self.plot = None
def testApi(self):
"""Test availability of the API"""
self.plot.getXAxis().setLimitsConstraints(minPos=1, maxPos=10)
self.plot.getXAxis().setRangeConstraints(minRange=1, maxRange=1)
self.plot.getYAxis().setLimitsConstraints(minPos=1, maxPos=10)
self.plot.getYAxis().setRangeConstraints(minRange=1, maxRange=1)
def testXMinMax(self):
"""Test limit constains on x-axis"""
self.plot.getXAxis().setLimitsConstraints(minPos=0, maxPos=100)
self.plot.setLimits(xmin=-1, xmax=101, ymin=-1, ymax=101)
self.assertEqual(self.plot.getXAxis().getLimits(), (0, 100))
self.assertEqual(self.plot.getYAxis().getLimits(), (-1, 101))
def testYMinMax(self):
"""Test limit constains on y-axis"""
self.plot.getYAxis().setLimitsConstraints(minPos=0, maxPos=100)
self.plot.setLimits(xmin=-1, xmax=101, ymin=-1, ymax=101)
self.assertEqual(self.plot.getXAxis().getLimits(), (-1, 101))
self.assertEqual(self.plot.getYAxis().getLimits(), (0, 100))
def testMinXRange(self):
"""Test min range constains on x-axis"""
self.plot.getXAxis().setRangeConstraints(minRange=100)
self.plot.setLimits(xmin=1, xmax=99, ymin=1, ymax=99)
limits = self.plot.getXAxis().getLimits()
self.assertEqual(limits[1] - limits[0], 100)
limits = self.plot.getYAxis().getLimits()
self.assertNotEqual(limits[1] - limits[0], 100)
def testMaxXRange(self):
"""Test max range constains on x-axis"""
self.plot.getXAxis().setRangeConstraints(maxRange=100)
self.plot.setLimits(xmin=-1, xmax=101, ymin=-1, ymax=101)
limits = self.plot.getXAxis().getLimits()
self.assertEqual(limits[1] - limits[0], 100)
limits = self.plot.getYAxis().getLimits()
self.assertNotEqual(limits[1] - limits[0], 100)
def testMinYRange(self):
"""Test min range constains on y-axis"""
self.plot.getYAxis().setRangeConstraints(minRange=100)
self.plot.setLimits(xmin=1, xmax=99, ymin=1, ymax=99)
limits = self.plot.getXAxis().getLimits()
self.assertNotEqual(limits[1] - limits[0], 100)
limits = self.plot.getYAxis().getLimits()
self.assertEqual(limits[1] - limits[0], 100)
def testMaxYRange(self):
"""Test max range constains on y-axis"""
self.plot.getYAxis().setRangeConstraints(maxRange=100)
self.plot.setLimits(xmin=-1, xmax=101, ymin=-1, ymax=101)
limits = self.plot.getXAxis().getLimits()
self.assertNotEqual(limits[1] - limits[0], 100)
limits = self.plot.getYAxis().getLimits()
self.assertEqual(limits[1] - limits[0], 100)
def testChangeOfConstraints(self):
"""Test changing of the constraints"""
self.plot.getXAxis().setRangeConstraints(minRange=10, maxRange=10)
# There is no more constraints on the range
self.plot.getXAxis().setRangeConstraints(minRange=None, maxRange=None)
self.plot.setLimits(xmin=-1, xmax=101, ymin=-1, ymax=101)
self.assertEqual(self.plot.getXAxis().getLimits(), (-1, 101))
def testSettingConstraints(self):
"""Test setting a constaint (setLimits first then the constaint)"""
self.plot.setLimits(xmin=-1, xmax=101, ymin=-1, ymax=101)
self.plot.getXAxis().setLimitsConstraints(minPos=0, maxPos=100)
self.assertEqual(self.plot.getXAxis().getLimits(), (0, 100))
示例14: setActiveCurve
def setActiveCurve(self, legend, replot=True):
return PlotWidget.setActiveCurve(self, legend)
示例15: SilxMaskImageWidget
class SilxMaskImageWidget(qt.QMainWindow):
"""Main window with a plot widget, a toolbar and a slider.
A list of images can be set with :meth:`setImages`.
The mask can be accessed through getter and setter methods:
:meth:`setSelectionMask` and :meth:`getSelectionMask`.
The plot widget can be accessed as :attr:`plot`. It is a silx
plot widget.
The toolbar offers some basic interaction tools:
zoom control, colormap, aspect ratio, y axis orientation,
"save image" menu and a mask widget.
"""
sigMaskImageWidget = qt.pyqtSignal(object)
def __init__(self, parent=None):
qt.QMainWindow.__init__(self, parent=parent)
if parent is not None:
# behave as a widget
self.setWindowFlags(qt.Qt.Widget)
else:
self.setWindowTitle("PyMca - Image Selection Tool")
centralWidget = qt.QWidget(self)
layout = qt.QVBoxLayout(centralWidget)
centralWidget.setLayout(layout)
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(0)
# Plot
self.plot = PlotWidget(parent=centralWidget)
self.plot.setWindowFlags(qt.Qt.Widget)
self.plot.setDefaultColormap({'name': 'temperature',
'normalization': 'linear',
'autoscale': True,
'vmin': 0.,
'vmax': 1.})
layout.addWidget(self.plot)
# Mask Widget
self._maskToolsDockWidget = None
# Image selection slider
self.slider = qt.QSlider(self.centralWidget())
self.slider.setOrientation(qt.Qt.Horizontal)
self.slider.setMinimum(0)
self.slider.setMaximum(0)
layout.addWidget(self.slider)
self.slider.valueChanged[int].connect(self.showImage)
# ADD/REMOVE/REPLACE IMAGE buttons
buttonBox = qt.QWidget(self)
buttonBoxLayout = qt.QHBoxLayout(buttonBox)
buttonBoxLayout.setContentsMargins(0, 0, 0, 0)
buttonBoxLayout.setSpacing(0)
self.addImageButton = qt.QPushButton(buttonBox)
icon = qt.QIcon(qt.QPixmap(IconDict["rgb16"]))
self.addImageButton.setIcon(icon)
self.addImageButton.setText("ADD IMAGE")
self.addImageButton.setToolTip("Add image to RGB correlator")
buttonBoxLayout.addWidget(self.addImageButton)
self.removeImageButton = qt.QPushButton(buttonBox)
self.removeImageButton.setIcon(icon)
self.removeImageButton.setText("REMOVE IMAGE")
self.removeImageButton.setToolTip("Remove image from RGB correlator")
buttonBoxLayout.addWidget(self.removeImageButton)
self.replaceImageButton = qt.QPushButton(buttonBox)
self.replaceImageButton.setIcon(icon)
self.replaceImageButton.setText("REPLACE IMAGE")
self.replaceImageButton.setToolTip(
"Replace all images in RGB correlator with this one")
buttonBoxLayout.addWidget(self.replaceImageButton)
self.addImageButton.clicked.connect(self._addImageClicked)
self.removeImageButton.clicked.connect(self._removeImageClicked)
self.replaceImageButton.clicked.connect(self._replaceImageClicked)
layout.addWidget(buttonBox)
# median filter widget
self._medianParameters = {'row_width': 1,
'column_width': 1,
'conditional': 0}
self._medianParametersWidget = MedianParameters(self,
use_conditional=True)
self._medianParametersWidget.widthSpin.setValue(1)
self._medianParametersWidget.widthSpin.valueChanged[int].connect(
self._setMedianKernelWidth)
self._medianParametersWidget.conditionalSpin.valueChanged[int].connect(
self._setMedianConditionalFlag)
layout.addWidget(self._medianParametersWidget)
# motor positions (hidden by default)
self.motorPositionsWidget = MotorInfoWindow.MotorInfoDialog(self,
[""],
[{}])
#.........这里部分代码省略.........