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


Python FigureCanvasQTAgg.repaint方法代码示例

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


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

示例1: CourseMapDialog

# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import repaint [as 别名]
class CourseMapDialog(QtGui.QDialog):
    """Implements a dialog box to display course maps."""

    time_slider_changed = QtCore.Signal(float)

    def __init__(self, parent):
        QtGui.QDialog.__init__(self, parent)
        self._ui = ui_course_map_dialog.Ui_Dialog()
        self._ui.setupUi(self)

        params = matplotlib.figure.SubplotParams(0, 0, 1, 1, 0, 0)
        self._figure = matplotlib.figure.Figure(subplotpars=params)
        self._canvas = FigureCanvas(self._figure)
        self._canvas.mpl_connect('motion_notify_event', self._handle_mouse)
        self._canvas.mpl_connect('scroll_event', self._handle_scroll)
        self._canvas.mpl_connect('button_release_event',
                                 self._handle_mouse_release)
        self._mouse_start = None

        # Make QT drawing not be super slow.  See:
        # https://github.com/matplotlib/matplotlib/issues/2559/
        def draw():
            FigureCanvas.draw(self._canvas)
            self._canvas.repaint()

        self._canvas.draw = draw
        self._plot = self._figure.add_subplot(111)

        self._gdal_source = course_gdal.GdalSource()
        self._gdal = None

        layout = QtGui.QVBoxLayout(self._ui.mapFrame)
        layout.addWidget(self._canvas, 1)

        self._log_data = dict()

        # TODO sammy make COLORS a project wide config
        self._COLORS = 'rgbcmyk'
        self._next_color = 0
        self._bounds = ((0, 0), (0, 0))
        self._time_current = 0
        self._total_time = 0
        self._ui.timeSlider.valueChanged.connect(self._handle_time_slider)

    def add_log(self, log_name, log):
        log_data = _LogMapData(log_name, log, self._COLORS[self._next_color])
        self._log_data[log_name] = log_data
        self._next_color = (self._next_color + 1) % len(self._COLORS)

        if self._gdal is None:
            self._gdal = self._gdal_source.get_gdal(
                log_data.utm_data[0][1], log_data.utm_data[0][2])
            if self._gdal is not None:
                self._plot.imshow(self._gdal.image, extent=self._gdal.extent)

        self._plot.add_line(log_data.line)
        self._plot.add_line(log_data.marker)
        self._plot.legend(loc=2)
        self._update_scale()

    def update_sync(self):
        for log_data in self._log_data.itervalues():
            log_data.update_line_data()
            log_data.update_marker(self._time_current)

        self._update_scale()

    def _update_scale(self):
        self._plot.relim()
        minx = 1e10
        miny = 1e10
        maxx = -1e10
        maxy = -1e10
        max_time = 0

        for log_data in self._log_data.itervalues():
            bounds = log_data.bounds
            minx = min(minx, bounds[0][0])
            miny = min(miny, bounds[0][1])
            maxx = max(maxx, bounds[1][0])
            maxy = max(maxy, bounds[1][1])
            max_time = max(max_time, log_data.utm_data[-1][0])
        self._total_time = max_time

        x_size = maxx - minx
        y_size = maxy - miny
        xy_delta = x_size - y_size
        if xy_delta > 0:
            miny -= xy_delta / 2
            maxy += xy_delta / 2
        else:
            minx += xy_delta / 2
            maxx -= xy_delta / 2

        self._bounds = ((minx, miny), (maxx, maxy))
        self._plot.set_xlim(left=minx, right=maxx)
        self._plot.set_ylim(bottom=miny, top=maxy)
        self._canvas.draw()

    def _handle_mouse(self, event):
#.........这里部分代码省略.........
开发者ID:sammy-net,项目名称:racedataviz,代码行数:103,代码来源:course_map_dialog.py

示例2: Tplot

# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import repaint [as 别名]
class Tplot(QtGui.QMainWindow):
    def __init__(self):
        super(Tplot, self).__init__()

        self.ui = ui_tplot_main_window.Ui_TplotMainWindow()
        self.ui.setupUi(self)

        self.figure = matplotlib.figure.Figure()
        self.canvas = FigureCanvas(self.figure)

        self.canvas.mpl_connect('motion_notify_event', self.handle_mouse)
        self.canvas.mpl_connect('key_press_event', self.handle_key_press)
        self.canvas.mpl_connect('key_release_event', self.handle_key_release)

        # Make QT drawing not be super slow.  See:
        # https://github.com/matplotlib/matplotlib/issues/2559/
        def draw():
            FigureCanvas.draw(self.canvas)
            self.canvas.repaint()

        self.canvas.draw = draw

        self.left_axis = self.figure.add_subplot(111)
        self.left_axis.tplot_name = 'Left'

        self.axes = {
            'Left' : self.left_axis,
            }

        layout = QtGui.QVBoxLayout(self.ui.plotFrame)
        layout.addWidget(self.canvas, 1)

        self.toolbar = backend_qt4agg.NavigationToolbar2QT(self.canvas, self)
        self.addToolBar(self.toolbar)

        self.canvas.setFocusPolicy(QtCore.Qt.ClickFocus)
        self.canvas.setFocus()

        self.log = None
        self.COLORS = 'rgbcmyk'
        self.next_color = 0

        self.timer = QtCore.QTimer()
        self.timer.timeout.connect(self.handle_timeout)

        self.time_start = None
        self.time_end = None
        self.time_current = None

        self.ui.recordCombo.currentIndexChanged.connect(
            self.handle_record_combo)
        self.ui.addPlotButton.clicked.connect(self.handle_add_plot_button)
        self.ui.removeButton.clicked.connect(self.handle_remove_button)
        self.ui.treeWidget.itemExpanded.connect(self.handle_item_expanded)
        self.tree_items = []
        self.ui.treeWidget.header().setResizeMode(
            QtGui.QHeaderView.ResizeToContents)
        self.ui.timeSlider.valueChanged.connect(self.handle_time_slider)
        self._updating_slider = BoolGuard()

        self.ui.fastReverseButton.clicked.connect(
            self.handle_fast_reverse_button)
        self.ui.stepBackButton.clicked.connect(
            self.handle_step_back_button)
        self.ui.playReverseButton.clicked.connect(
            self.handle_play_reverse_button)
        self.ui.stopButton.clicked.connect(self.handle_stop_button)
        self.ui.playButton.clicked.connect(self.handle_play_button)
        self.ui.stepForwardButton.clicked.connect(
            self.handle_step_forward_button)
        self.ui.fastForwardButton.clicked.connect(
            self.handle_fast_forward_button)

    def open(self, filename):
        try:
            maybe_log = Log(filename)
        except Exception as e:
            QtGui.QMessageBox.warning(self, 'Could not open log',
                                      'Error: ' + str(e))
            raise
            return

        # OK, we're good, clear out our UI.
        self.ui.treeWidget.clear()
        self.tree_items = []
        self.ui.recordCombo.clear()
        self.ui.xCombo.clear()
        self.ui.yCombo.clear()

        self.log = maybe_log
        for name in self.log.records.keys():
            self.ui.recordCombo.addItem(name)

            item = QtGui.QTreeWidgetItem()
            item.setText(0, name)
            self.ui.treeWidget.addTopLevelItem(item)
            self.tree_items.append(item)

            exemplar = self.log.records[name]
            def add_item(parent, element):
#.........这里部分代码省略.........
开发者ID:mjbots,项目名称:mjmech,代码行数:103,代码来源:tplot.py

示例3: PlotWidget

# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import repaint [as 别名]
class PlotWidget(QtGui.QWidget):
    COLORS = "rbgcmyk"

    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.history_s = 20.0
        self.next_color = 0
        self.paused = False

        self.figure = matplotlib.figure.Figure()
        self.canvas = FigureCanvas(self.figure)

        self.canvas.mpl_connect("key_press_event", self.handle_key_press)
        self.canvas.mpl_connect("key_release_event", self.handle_key_release)

        self.left_axis = self.figure.add_subplot(111)
        self.left_axis.grid()
        self.left_axis.fmt_xdata = lambda x: "%.3f" % x

        self.left_axis.legend_loc = LEFT_LEGEND_LOC

        self.right_axis = None

        def draw():
            # NOTE jpieper: For some reason, on the first repaint
            # event, the height is negative, which throws spurious
            # errors.  Paper over that here.
            l, b, w, h = self.figure.bbox.bounds
            if h < 0:
                return
            FigureCanvas.draw(self.canvas)
            self.canvas.repaint()

        self.canvas.draw = draw

        self.toolbar = backend_qt4agg.NavigationToolbar2QT(self.canvas, self)
        self.pause_action = QtGui.QAction(u"Pause", self)
        self.pause_action.setCheckable(True)
        self.pause_action.toggled.connect(self._handle_pause)
        self.toolbar.addAction(self.pause_action)

        layout = QtGui.QVBoxLayout(self)
        layout.addWidget(self.toolbar, 0)
        layout.addWidget(self.canvas, 1)

        self.canvas.setFocusPolicy(QtCore.Qt.ClickFocus)

    def _handle_pause(self, value):
        self.paused = value

    def add_plot(self, name, signal, axis_number):
        axis = self.left_axis
        if axis_number == 1:
            if self.right_axis is None:
                self.right_axis = self.left_axis.twinx()
                self.right_axis.legend_loc = RIGHT_LEGEND_LOC
            axis = self.right_axis
        item = PlotItem(axis, self, name, signal)
        return item

    def remove_plot(self, item):
        item.remove()

    def _get_axes_keys(self):
        result = []
        result.append(("1", self.left_axis))
        if self.right_axis:
            result.append(("2", self.right_axis))
        return result

    def handle_key_press(self, event):
        if event.key not in ["1", "2"]:
            return
        for key, axis in self._get_axes_keys():
            if key == event.key:
                axis.set_navigate(True)
            else:
                axis.set_navigate(False)

    def handle_key_release(self, event):
        if event.key not in ["1", "2"]:
            return
        for key, axis in self._get_axes_keys():
            axis.set_navigate(True)
开发者ID:mjbots,项目名称:mjmech,代码行数:87,代码来源:tview.py


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