当前位置: 首页>>代码示例>>Python>>正文


Python PlotWidget.addImage方法代码示例

本文整理汇总了Python中silx.gui.plot.PlotWidget.addImage方法的典型用法代码示例。如果您正苦于以下问题:Python PlotWidget.addImage方法的具体用法?Python PlotWidget.addImage怎么用?Python PlotWidget.addImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在silx.gui.plot.PlotWidget的用法示例。


在下文中一共展示了PlotWidget.addImage方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestActiveImageAlphaSlider

# 需要导入模块: from silx.gui.plot import PlotWidget [as 别名]
# 或者: from silx.gui.plot.PlotWidget import addImage [as 别名]
class TestActiveImageAlphaSlider(TestCaseQt):
    def setUp(self):
        super(TestActiveImageAlphaSlider, self).setUp()
        self.plot = PlotWidget()
        self.aslider = AlphaSlider.ActiveImageAlphaSlider(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()

    def tearDown(self):
        self.qapp.processEvents()
        self.plot.setAttribute(qt.Qt.WA_DeleteOnClose)
        self.plot.close()
        del self.plot
        del self.aslider

        super(TestActiveImageAlphaSlider, self).tearDown()

    def testWidgetEnabled(self):
        # no active image initially, slider must be deactivate
        self.assertFalse(self.aslider.isEnabled())

        self.plot.addImage(numpy.array([[0, 1, 2], [3, 4, 5]]))
        # now we have an active image
        self.assertTrue(self.aslider.isEnabled())

        self.plot.setActiveImage(None)
        self.assertFalse(self.aslider.isEnabled())

    def testGetImage(self):
        self.plot.addImage(numpy.array([[0, 1, 2], [3, 4, 5]]))
        self.assertEqual(self.plot.getActiveImage(),
                         self.aslider.getItem())

        self.plot.addImage(numpy.array([[0, 1, 3], [2, 4, 6]]), legend="2")
        self.plot.setActiveImage("2")
        self.assertEqual(self.plot.getImage("2"),
                         self.aslider.getItem())

    def testGetAlpha(self):
        self.plot.addImage(numpy.array([[0, 1, 2], [3, 4, 5]]), legend="1")
        self.aslider.setValue(137)
        self.assertAlmostEqual(self.aslider.getAlpha(),
                               137. / 255)
开发者ID:vallsv,项目名称:silx,代码行数:54,代码来源:testAlphaSlider.py

示例2: addImage

# 需要导入模块: from silx.gui.plot import PlotWidget [as 别名]
# 或者: from silx.gui.plot.PlotWidget import addImage [as 别名]
 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)
开发者ID:vasole,项目名称:pymca,代码行数:18,代码来源:SilxBackend.py

示例3: PlotWidget

# 需要导入模块: from silx.gui.plot import PlotWidget [as 别名]
# 或者: from silx.gui.plot.PlotWidget import addImage [as 别名]
    from PyMca5 import PyMcaPlugins
    import os
    from silx.test.utils import add_relative_noise
    from silx.gui.plot import PlotWidget

    # build a plot widget with a plugin toolbar button
    app = qt.QApplication([])
    master_plot = PlotWidget()
    toolb = qt.QToolBar(master_plot)
    plugins_tb_2d = PluginsToolButton(plot=master_plot,
                                      parent=toolb,
                                      method="getPlugin2DInstance")
    plugins_tb_2d.getPlugins(
                    method="getPlugin2DInstance",
                    directoryList=[os.path.dirname(PyMcaPlugins.__file__)])
    toolb.addWidget(plugins_tb_2d)
    master_plot.addToolBar(toolb)
    master_plot.show()

    # add a noisy image
    a, b = numpy.meshgrid(numpy.linspace(-10, 10, 500),
                          numpy.linspace(-10, 5, 400),
                          indexing="ij")
    myimg = numpy.asarray(numpy.sin(a * b) / (a * b),
                          dtype='float32')
    myimg = add_relative_noise(myimg,
                               max_noise=10.)    # %
    master_plot.addImage(myimg)

    app.exec_()
开发者ID:maurov,项目名称:pymca,代码行数:32,代码来源:Medfilt2DPlugin.py

示例4: SilxMaskImageWidget

# 需要导入模块: from silx.gui.plot import PlotWidget [as 别名]
# 或者: from silx.gui.plot.PlotWidget import addImage [as 别名]
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,
                                                                    [""],
                                                                    [{}])
#.........这里部分代码省略.........
开发者ID:maurov,项目名称:pymca,代码行数:103,代码来源:SilxMaskImageWidget.py

示例5: ValueError

# 需要导入模块: from silx.gui.plot import PlotWidget [as 别名]
# 或者: from silx.gui.plot.PlotWidget import addImage [as 别名]
        if maxValue == 1:
            startIndex = 1
            colors = numpy.zeros((2, 4), dtype=numpy.uint8)
            colors[1, 3] = 255
        else:
            raise ValueError("Different mask levels require color list input")
    oldShape = pixmap.shape
    pixmap.shape = -1, 4
    maskView = mask[:]
    maskView.shape = -1,
    blendFactor = 0.8
    for i in range(startIndex, maxValue + 1):
        idx = (maskView==i)
        pixmap[idx, :] = pixmap[idx, :] * blendFactor + \
                         colors[i] * (1.0 - blendFactor)
    pixmap.shape = oldShape
    return pixmap

if __name__ == "__main__":
    from PyMca5.PyMcaGui import PyMcaQt as qt
    from silx.gui.plot import PlotWidget
    app = qt.QApplication([])
    w = PlotWidget()
    data = numpy.arange(10000.).reshape(100, 100)
    mask = numpy.zeros(data.shape, dtype=numpy.uint8)
    mask[25:75, 25:75] = 1
    image = getPixmapFromData(data, mask=mask)
    w.addImage(image, mask=mask)
    w.show()
    app.exec_()
开发者ID:maurov,项目名称:pymca,代码行数:32,代码来源:MaskImageTools.py

示例6: MaskScatterWidget

# 需要导入模块: from silx.gui.plot import PlotWidget [as 别名]
# 或者: from silx.gui.plot.PlotWidget import addImage [as 别名]
class MaskScatterWidget(qt.QMainWindow):
    """Simple plot widget designed to display a scatter plot on top
    of a background image.

    A transparency slider is provided to adjust the transparency of the
    scatter points.

    A mask tools widget is provided to select/mask points of the scatter
    plot.
    """
    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)

    def setSelectionMask(self, mask, copy=True):
        """Set the mask to a new array.

        :param numpy.ndarray mask: The array to use for the mask.
                    Mask type: array of uint8 of dimension 1,
                    Array of other types are converted.
        :param bool copy: True (the default) to copy the array,
                          False to use it as is if possible.
        :return: None if failed, shape of mask as 1-tuple if successful.
        """
        return self._maskToolsWidget.setSelectionMask(mask,
                                                      copy=copy)

    def getSelectionMask(self, copy=True):
        """Get the current mask as a 1D array.

        :param bool copy: True (default) to get a copy of the mask.
                          If False, the returned array MUST not be modified.
        :return: The array of the mask with dimension of the scatter data.
                 If there is no scatter data, None is returned.
        :rtype: 1D numpy.ndarray of uint8
        """
        return self._maskToolsWidget.getSelectionMask(copy=copy)

    def setBackgroundImage(self, image, xscale=(0, 1.), yscale=(0, 1.),
                           colormap=None):
        """Set a background image

        :param image: 2D image, array of shape (nrows, ncolumns)
            or (nrows, ncolumns, 3) or (nrows, ncolumns, 4) RGB(A) pixmap
        :param xscale: Factors for polynomial scaling  for x-axis,
            *(a, b)* such as :math:`x \mapsto a + bx`
        :param yscale: Factors for polynomial scaling  for y-axis
        """
        self._plot.addImage(image, legend=self._bgImageLegend,
                            origin=(xscale[0], yscale[0]),
                            scale=(xscale[1], yscale[1]),
                            z=0,
                            colormap=colormap)

    def setScatter(self, x, y, v=None, info=None, colormap=None):
        """Set the scatter data, by providing its data as a 1D
        array or as a pixmap.

        The scatter plot set through this method is associated
        with the transparency slider.

        :param x: 1D array of x coordinates
        :param y: 1D array of y coordinates
        :param v: Array of values for each point, represented as the color
             of the point on the plot.
        """
        self._plot.addScatter(x, y, v, legend=self._activeScatterLegend,
                              info=info, colormap=colormap)
        # the mask is associated with the active scatter
        self._plot._setActiveItem(kind="scatter",
                                  legend=self._activeScatterLegend)

        self._alphaSlider.setLegend(self._activeScatterLegend)
开发者ID:dnaudet,项目名称:silx,代码行数:97,代码来源:scatterMask.py


注:本文中的silx.gui.plot.PlotWidget.addImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。