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


Python PlotWidget._setActiveItem方法代码示例

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


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

示例1: MaskScatterWidget

# 需要导入模块: from silx.gui.plot import PlotWidget [as 别名]
# 或者: from silx.gui.plot.PlotWidget import _setActiveItem [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._setActiveItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。