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


Python FigureCanvasQTAgg.draw_idle方法代码示例

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


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

示例1: MplWidget

# 需要导入模块: from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg import draw_idle [as 别名]
class MplWidget(QtWidgets.QWidget):
    def __init__(self, parent=None):
        QtWidgets.QWidget.__init__(self, parent)

        self.fig = Figure()
        self.canvas = FigureCanvas(self.fig)
        self.canvas.setFocusPolicy(QtCore.Qt.ClickFocus)
        self.canvas.setFocus()
        self.canvas.setParent(self)
        self.canvas.mpl_connect('scroll_event', self.onWheel)
        self.canvas.mpl_connect('button_press_event', self.start_pan)
        self.canvas.mpl_connect('button_release_event', self.pan)
        self.canvas.mpl_connect('motion_notify_event', self.pan_motion)

        self.axes = self.fig.add_subplot(111)
        self.fig.tight_layout()

        self.dragx = None
        self.dragy = None
        # self.mpl_toolbar = NavigationToolbar(self.canvas, self)

        vbox = QtWidgets.QVBoxLayout()
        vbox.addWidget(self.canvas)
        # vbox.addWidget(self.mpl_toolbar)
        self.setLayout(vbox)

    def start_pan(self, event):
        if event.button == 3:
            self.dragx, self.dragy = event.xdata, event.ydata

    def do_pan(self, xdata, ydata):
        diffx, diffy = self.dragx - xdata, self.dragy - ydata
        x1, x2 = self.axes.get_xlim()
        y1, y2 = self.axes.get_ylim()
        self.axes.set_xlim(x1 + diffx, x2 + diffx)
        self.axes.set_ylim(y1 + diffy, y2 + diffy)
        self.canvas.draw_idle()

    def stop_pan(self):
        self.dragx, self.dragy = None, None

    def pan(self, event):
        if event.button == 3:
            if event.inaxes is not None and \
                        self.dragx is not None and self.dragy is not None and \
                        event.xdata is not None and event.ydata is not None:
                self.do_pan(event.xdata, event.ydata)
            self.stop_pan()

    def pan_motion(self, event):
        if event.inaxes is not None and \
                        self.dragx is not None and self.dragy is not None and \
                        event.xdata is not None and event.ydata is not None:
            self.do_pan(event.xdata, event.ydata)

    def _rescale(self, lo, hi, step, pt=None, bal=None, scale='linear'):
        """
        Rescale (lo,hi) by step, returning the new (lo,hi)
        The scaling is centered on pt, with positive values of step
        driving lo/hi away from pt and negative values pulling them in.
        If bal is given instead of point, it is already in [0,1] coordinates.

        This is a helper function for step-based zooming.
        """
        # Convert values into the correct scale for a linear transformation
        # TODO: use proper scale transformers
        if scale == 'log':
            lo, hi = math.log10(lo), math.log10(hi)
            if pt is not None: pt = math.log10(pt)

        # Compute delta from axis range * %, or 1-% if percent is negative
        if step > 0:
            delta = float(hi - lo) * step / 100
        else:
            delta = float(hi - lo) * step / (100 - step)

        # Add scale factor proportionally to the lo and hi values, preserving the
        # point under the mouse
        if bal is None:
            bal = float(pt - lo) / (hi - lo)
        lo -= bal * delta
        hi += (1 - bal) * delta

        # Convert transformed values back to the original scale
        if scale == 'log':
            lo, hi = math.pow(10., lo), math.pow(10., hi)

        return (lo, hi)

    def onWheel(self, event):
        """
        Process mouse wheel as zoom events
        """
        ax = event.inaxes

        # Older versions of matplotlib do not have event.step defined
        try:
            step = 20.0 * event.step
        except:
            if event.button == 'up':
#.........这里部分代码省略.........
开发者ID:nlw0,项目名称:safl,代码行数:103,代码来源:mplwidget.py


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