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


Python FigureCanvasQTAgg.draw方法代码示例

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


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

示例1: ColorbarWidget

# 需要导入模块: from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg import draw [as 别名]
class ColorbarWidget(QWidget):

    def __init__(self, parent=None):
        super(ColorbarWidget, self).__init__(parent)
        fig = Figure()
        rect = 0.25, 0.05, 0.1, 0.90
        self.cb_axes = fig.add_axes(rect)
        self.canvas = FigureCanvas(fig)
        self.setLayout(QVBoxLayout())
        self.layout().addWidget(self.canvas)
        self.button = QPushButton("Update")
        self.layout().addWidget(self.button)
        self.button.pressed.connect(self._update_cb_scale)

        self._create_colorbar(fig)

    def _create_colorbar(self, fig):
        self.mappable = ScalarMappable(norm=SymLogNorm(0.0001, 1,vmin=-10., vmax=10000.),
                                  cmap=DEFAULT_CMAP)
        self.mappable.set_array([])
        fig.colorbar(self.mappable, ax=self.cb_axes, cax=self.cb_axes)

    def _update_cb_scale(self):
        self.mappable.colorbar.remove()
        rect = 0.25, 0.05, 0.1, 0.90
        self.cb_axes = self.canvas.figure.add_axes(rect)
        self.mappable = ScalarMappable(Normalize(30, 4300),
                                   cmap=DEFAULT_CMAP)
        self.mappable.set_array([])
        self.canvas.figure.colorbar(self.mappable, ax=self.cb_axes, cax=self.cb_axes)
        self.canvas.draw()
开发者ID:martyngigg,项目名称:sandbox,代码行数:33,代码来源:cbar.py

示例2: Statistics

# 需要导入模块: from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg import draw [as 别名]
class Statistics():
    def __init__(self, stat_label, parent, width=3, height=4, dpi=100):

        self.fig = Figure(figsize=(width, height), dpi=dpi)
        self.axes = self.fig.add_subplot(111)
        self.axes.hold(False)

        self.canvas = FigureCanvasQTAgg(self.fig)
        parent.addWidget(self.canvas, 1, 0, 1, 1)

        self.canvas.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.Expanding)
        self.canvas.updateGeometry()

        self.stat_label = stat_label;
        self.reset()

    def refresh(self, stats):
        # stats.print()
        _translate = QtCore.QCoreApplication.translate
        self.stat_label.setText(_translate("MainWindow", stats.print()))
        # counters
        foodCnt = stats.foodCnt()
        self.foods.append(foodCnt.existing)
        self.stepNumbers.append(stats.stepNumber())
        # plot
        self.axes.plot(self.stepNumbers, self.foods)
        self.axes.set_xlabel("Step number")
        self.axes.set_ylabel("Food count")
        self.canvas.draw()

    def reset(self):
        self.foods = []
        self.stepNumbers = []
开发者ID:Kamilcuk,项目名称:Anthill,代码行数:35,代码来源:mainWindow.py

示例3: PlotWidget

# 需要导入模块: from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg import draw [as 别名]
class PlotWidget(QtWidgets.QWidget):
	def __init__(self, parent=None):
		QtWidgets.QWidget.__init__(self, parent)
		self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
		
		self.figure = plt.figure()
		
		self.canvas = FigureCanvas(self.figure)
		
		self.toolbar = NavigationToolbar(self.canvas, self)
		
		self.button = QtWidgets.QPushButton("Plot")
		self.button.clicked.connect(self.plot)
		
		layout = QtWidgets.QVBoxLayout()
		layout.addWidget(self.toolbar)
		layout.addWidget(self.canvas)
		layout.addWidget(self.button)
		
		self.setLayout(layout)
	
	def plot(self):
		data = [x for x in range(10)]
		
		ax = self.figure.add_subplot(111)
		
		ax.hold(False)
		
		ax.plot(data, "*-")
		
		self.canvas.draw()
开发者ID:neXyon,项目名称:pynephoscope,代码行数:33,代码来源:main.py

示例4: Window

# 需要导入模块: from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg import draw [as 别名]
class Window(QDialog):
#    https://stackoverflow.com/questions/12459811/how-to-embed-matplotlib-in-pyqt-for-dummies
    
    def __init__(self, parent=None):
        super(Window, self).__init__(parent)

        # a figure instance to plot on
        self.figure = plt.figure()

        # this is the Canvas Widget that displays the `figure`
        # it takes the `figure` instance as a parameter to __init__
        self.canvas = FigureCanvas(self.figure)

        # this is the Navigation widget
        # it takes the Canvas widget and a parent
        self.toolbar = NavigationToolbar(self.canvas, self)

        # Just some button connected to `plot` method
        self.button = QPushButton('Plot')
        self.button.clicked.connect(self.plot)

        # set the layout
        layout = QVBoxLayout()
        layout.addWidget(self.toolbar)
        layout.addWidget(self.canvas)
        layout.addWidget(self.button)
        self.setLayout(layout)

    def plot(self):
        ''' plot some random stuff '''
        # random data
        data = [random.random() for i in range(10)]

        # instead of ax.hold(False)
        self.figure.clear()

        # create an axis
        ax = self.figure.add_subplot(111)

        # discards the old graph
        # ax.hold(False) # deprecated, see above

        # plot data
        ax.plot(data, '*-')

        # refresh canvas
        self.canvas.draw()

    def keyPressEvent(self, event):
        
        # http://zetcode.com/gui/pyqt5/eventssignals/
        
      if event.key() == QtCore.Qt.Key_Escape:
         self.close()
      if event.key() == QtCore.Qt.Key_Space:
        global gridLayout
        item = gridLayout.itemAtPosition(1,1)
        w = item.widget()
        w.setText("test")
开发者ID:henrythroop,项目名称:NH_Jring2,代码行数:61,代码来源:test_qt_plot.py

示例5: RadarUI

# 需要导入模块: from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg import draw [as 别名]
class RadarUI(QtWidgets.QWidget):
# class RadarUI(QtWidgets.QMainWindow):

    def __init__(self):
        super(RadarUI, self).__init__()
        self.__controller = None
        self.__init_ui()

    def __init_ui(self):
        remove_clutter = QtWidgets.QPushButton('Remove Clutter', self)
        restore_clutter = QtWidgets.QPushButton('Restore Clutter', self)

        remove_clutter.clicked.connect(self.remove_clutter)
        restore_clutter.clicked.connect(self.restore_clutter)

        buttons_layout = QtWidgets.QHBoxLayout()
        buttons_layout.addWidget(remove_clutter)
        buttons_layout.addWidget(restore_clutter)

        figure = Figure()
        self.__controller = controller.Controller(figure)
        self.__controller.update.connect(self.__update_label)

        ax = figure.add_subplot(212)
        self.__line, = ax.plot(range(10))

        self.__canvas = FigureCanvasQTAgg(figure)
        self.__canvas.show()

        self.__name_label = QtWidgets.QLabel("asdf")

        # main layout
        main_layout = QtWidgets.QVBoxLayout()
        main_layout.addStretch(1)
        main_layout.addWidget(self.__canvas)
        main_layout.addWidget(self.__name_label)
        main_layout.addLayout(buttons_layout)

        self.setLayout(main_layout)
        self.show()

    def remove_clutter(self):
        # todo
        x, y = self.__line.get_data()
        self.__line.set_ydata(y - 0.2 * x)
        self.__canvas.draw()

    def restore_clutter(self):
        # todo
        x, y = self.__line.get_data()
        self.__line.set_ydata(y + 0.2 * x)
        self.__canvas.draw()

    def run(self):
        self.__controller.run2()

    @QtCore.pyqtSlot(np.ndarray)
    def __update_label(self, value):
        self.__name_label.setText(str(value))
开发者ID:franciscoSoler,项目名称:mini,代码行数:61,代码来源:radar_ui.py

示例6: MainWindow

# 需要导入模块: from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg import draw [as 别名]
class MainWindow(QMainWindow, Ui_MainWindow):

    def __init__(self):
        super(MainWindow, self).__init__()
        self.setupUi(self)
        self.setWindowTitle('Fit Window')

        self._create_mplplot()
        self._peak_picker = self._create_peak_picker(self._canvas)

        self._onpick = self._canvas.mpl_connect('pick_event',
                                                self._on_pick)


    def _create_mplplot(self):
        x = np.arange(1,101, 0.01)
        mu, sigma = 50, 5
        y = np.exp( - (x - mu)**2 / (2 * sigma**2))
        fig = Figure()
        axes = fig.add_subplot(111)
        axes.plot(x, y, color='black')
        axes.set_title('Text', y=1.02)

        self._canvas = FigureCanvas(fig)
        print(dir(FigureCanvas))
        self._filter = MouseClickMonitor(self._canvas)
        self._canvas.installEventFilter(self._filter)
        self.mpllayout.addWidget(self._canvas)
        self._canvas.draw()
        return fig

    def _create_peak_picker(self, canvas):
        picker = PeakPickerTool(canvas)
        self.on_region_update(picker.lines[0].get_xdata()[0],
                              picker.lines[1].get_xdata()[0])
        picker.region_updated.connect(self.on_region_update)
        return picker

    def _on_pick(self, evt):
        if not evt.mouseevent.dblclick:
            return
        print(dir(evt.artist.get_text()))
        # print("Title double clicked at matplotlib coords",evt.mouseevent.x, evt.mouseevent.y)
        # print("Canvas width=",self._canvas.width(), "height=", self._canvas.height())
        # editor = QLineEdit(self._canvas)
        # editor.setAttribute(Qt.WA_DeleteOnClose)
        # editor.setText(self._canvas.figure.get_axes()[0].get_title())
        # self._canvas.figure.get_axes()[0].set_title('')
        # self._canvas.draw()
        # editor.move(evt.mouseevent.x - (0.5*editor.width()), self._canvas.height() - evt.mouseevent.y - 0.5*editor.height())
        # editor.show()
        # self._editor = editor


    def on_region_update(self, leftx, rightx):
        self.table_widget.setItem(0, 1, QTableWidgetItem(str(leftx)))
        self.table_widget.setItem(1, 1, QTableWidgetItem(str(rightx)))
开发者ID:martyngigg,项目名称:sandbox,代码行数:59,代码来源:peakpicker.py

示例7: PlotFigure

# 需要导入模块: from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg import draw [as 别名]
class PlotFigure(object):
    signals = []
    canvas = None

    def __init__(self, parent=None):
        self.fig = Figure(figsize=(600, 600),
                          dpi=72,
                          facecolor=(1, 1, 1),
                          edgecolor=(0, 0, 0))
        self.canvas = FigureCanvas(self.fig)

    def addSeries(self, series):
        self.rmSeries(series)
        # Add a new series
        if self.signals:
            if((self.signals[0].xunits == series.xunits) and
               (self.signals[0].yunits == series.yunits)):
                self.signals.append(series)
            else:
                self.signals = [series]
        else:
            self.signals = [series]

    def rmSeries(self, series):
        if self.signals:
            try:
                self.signals.remove(series)
            except:
                pass

    def clearSeries(self):
        self.signals = []

    def draw(self):
        self.ax = self.fig.add_subplot(1, 1, 1)
        self.ax.cla()
        for s in self.signals:
            self.ax.plot(s.xvalues, s.data, label=s.label)
        if len(self.signals):
            self.ax.set_xlabel(self.signals[0].xunits)
            self.ax.set_ylabel(self.signals[0].yunits)

        handles, labels = self.ax.get_legend_handles_labels()
        self.ax.legend(handles[::-1], labels[::-1])
        self.ax.legend(handles, labels)

        try:
            self.plotExtras()
        except:
            pass

        self.canvas.draw()

    def getWidget(self):
        return self.canvas
开发者ID:bnahill,项目名称:audiopulse-embedded,代码行数:57,代码来源:apulse_ui.py

示例8: test_resize_qt

# 需要导入模块: from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg import draw [as 别名]
def test_resize_qt():

    # This test just ensures that the code runs, but doesn't check for now
    # that the behavior is correct.

    pytest.importorskip('PyQt5')

    from PyQt5.QtWidgets import QMainWindow

    from matplotlib.figure import Figure
    from matplotlib.backends.backend_qt5 import FigureManagerQT
    from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg

    fig = Figure()
    canvas = FigureCanvasQTAgg(fig)
    canvas.manager = FigureManagerQT(canvas, 0)  # noqa
    ax = fig.add_subplot(1, 1, 1)

    canvas.draw = Mock(side_effect=canvas.draw)

    from matplotlib.backends.backend_qt5 import qApp

    window = QMainWindow()
    window.setCentralWidget(canvas)
    window.show()

    x1 = np.random.normal(0, 1, 10000000)
    y1 = np.random.normal(0, 1, 10000000)

    a = ScatterDensityArtist(ax, x1, y1)
    ax.add_artist(a)

    canvas.draw()
    assert not a.stale
    assert canvas.draw.call_count == 1

    window.resize(300, 300)

    # We can't actually check that stale is set to True since it only remains
    # so for a short amount of time, but we can check that draw is called twice
    # (once at the original resolution then once with the updated resolution).
    start = time.time()
    while time.time() - start < 1:
        qApp.processEvents()

    assert canvas.draw.call_count == 3

    assert not a.stale

    start = time.time()
    while time.time() - start < 1:
        qApp.processEvents()

    a.remove()
    qApp.processEvents()
开发者ID:astrofrog,项目名称:rasterized_scatter,代码行数:57,代码来源:test_scatter_density_artist.py

示例9: MainWindow

# 需要导入模块: from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg import draw [as 别名]
class MainWindow(QWidget):

    updGUI=pyqtSignal()
    def __init__(self, pose3d, parent=None):
        super(MainWindow, self).__init__(parent)
        
        layout = QGridLayout()
        
        self.seconds = 0
        self.MAXseconds = 900
        self.contSeconds = 0
        self.secondsArray = [0]
        
        self.devPercentajes = [0]
        self.percentaje = porcentajeWidget(self, pose3d)
        self.percentajePrev = 0
        self.figure = plt.figure()
        self.canvas = FigureCanvas(self.figure)
        
        layout.addWidget(self.canvas)
        
        vSpacer = QSpacerItem(30, 50, QSizePolicy.Ignored, QSizePolicy.Ignored)
        layout.addItem(vSpacer,1,0)
        
        self.setFixedSize(1200,500);
        
        self.setLayout(layout)
        
        timer = QTimer(self)
        timer.start(1000)
        timer.timeout.connect(self.contadorTime)
        

    def contadorTime(self):
        if self.seconds < self.MAXseconds:
            self.percentaje.updateG()
            self.seconds += 1
            if self.seconds % 2 == 0:
                self.contSeconds += 1
                dif = float(float(self.percentaje.porcentajeCasa) - float(self.percentajePrev))
                self.devPercentajes.append(dif)
                self.secondsArray.append(self.contSeconds)
                self.percentajePrev = self.percentaje.porcentajeCasa
            
            ax = self.figure.add_subplot(111)
            ax.set_xlabel('Time')
            ax.set_ylabel('Percentage Derivative')
            ax.set_xlim([0, 450]);
            ax.set_ylim([0, 0.7]);
            ax.plot(self.secondsArray, self.devPercentajes,'r')
            self.canvas.draw()
开发者ID:aitormf,项目名称:TeachingRobotics,代码行数:53,代码来源:graphicPercentaje.py

示例10: MyWindow

# 需要导入模块: from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg import draw [as 别名]
class MyWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.setupUI()

    def setupUI(self):
        self.setGeometry(600, 200, 1200, 600)
        self.setWindowTitle("PyChart Viewer v0.1")
        self.setWindowIcon(QIcon('icon.png'))

        self.lineEdit = QLineEdit()
        self.pushButton = QPushButton("차트그리기")
        self.pushButton.clicked.connect(self.pushButtonClicked)

        self.fig = plt.Figure()
        self.canvas = FigureCanvas(self.fig)

        leftLayout = QVBoxLayout()
        leftLayout.addWidget(self.canvas)

        # Right Layout
        rightLayout = QVBoxLayout()
        rightLayout.addWidget(self.lineEdit)
        rightLayout.addWidget(self.pushButton)
        rightLayout.addStretch(1)

        layout = QHBoxLayout()
        layout.addLayout(leftLayout)
        layout.addLayout(rightLayout)
        layout.setStretchFactor(leftLayout, 1)
        layout.setStretchFactor(rightLayout, 0)

        self.setLayout(layout)

    def pushButtonClicked(self):
        code = self.lineEdit.text()
        df = web.DataReader(code, "yahoo")
        df['MA20'] = df['Adj Close'].rolling(window=20).mean()
        df['MA60'] = df['Adj Close'].rolling(window=60).mean()

        ax = self.fig.add_subplot(111)
        ax.plot(df.index, df['Adj Close'], label='Adj Close')
        ax.plot(df.index, df['MA20'], label='MA20')
        ax.plot(df.index, df['MA60'], label='MA60')
        ax.legend(loc='upper right')
        ax.grid()

        self.canvas.draw()
开发者ID:pystockhub,项目名称:book,代码行数:50,代码来源:26.py

示例11: PlotWidget

# 需要导入模块: from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg import draw [as 别名]
class PlotWidget(QtWidgets.QFrame):

    SStats = pyqtSignal(np.ndarray, np.ndarray, np.ndarray, np.ndarray,
                        np.ndarray, np.ndarray)

    def __init__(self, parent=None):
        super(PlotWidget, self).__init__(parent)
        self.initUI()

    def initUI(self):
        self.figure = plt.figure()
        self.canvas = FigureCanvas(self.figure)
        self.toolbar = NavigationToolbar(self.canvas, self)

        layout = QtWidgets.QVBoxLayout()
        layout.addWidget(self.toolbar)
        layout.addWidget(self.canvas)
        self.setLayout(layout)

    def plot_sounding_axes(self):
        self.figure.clear()
        ax = self.figure.add_axes([0.05, 0.05, 0.90, 0.945])
        # ax = self.figure.add_axes([0.005,0.05,0.985,0.945])
        ax.hold(True)
        skewt.set_fontscalefactor(4)
        skewt.plot_sounding_axes(ax)
        self.canvas.draw()

    def plot_hodograph_axes(self):
        ax = self.figure.add_axes([0.005, 0.005, 0.985, 0.985])
        ax.hold(True)
        skewt.plot_hodo_axes(ax)
        self.canvas.draw()

    def plot_sounding(self, z, th, p, qv, u, v):
        self.figure.clear()
        # ax = self.figure.add_axes([0.005,0.05,0.985,0.945])
        ax = self.figure.add_axes([0.05, 0.05, 0.90, 0.945])
        ax.hold(True)
        skewt.plot_sounding_axes(ax)
        skewt.plot_sounding(ax, z, th, p, qv, u, v)
        self.canvas.draw()
        # Send data to stats widget
        self.SStats.emit(z, th, p, qv, u, v)

    def plot_hodograph(self, z, u, v):
        self.figure.clear()
        ax = self.figure.add_axes([0.005, 0.05, 0.985, 0.945])
        ax.hold(True)
        skewt.plot_hodo_axes(ax)
        skewt.plot_hodograph(ax, z, u, v)
        self.canvas.draw()
开发者ID:JorgeGacitua,项目名称:pyMeteo,代码行数:54,代码来源:PlotWidget.py

示例12: Window

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

        # a figure instance to plot on
        self.figure = plt.figure()

        # this is the Canvas Widget that displays the `figure`
        # it takes the `figure` instance as a parameter to __init__
        self.canvas = FigureCanvas(self.figure)

        # this is the Navigation widget
        # it takes the Canvas widget and a parent
        self.toolbar = NavigationToolbar(self.canvas, self)

        # Just some button connected to `plot` method
        self.button = QtWidgets.QPushButton('Plot')
        self.button.clicked.connect(self.plot)

        # set the layout
        layout = QtWidgets.QVBoxLayout()
        layout.addWidget(self.toolbar)
        layout.addWidget(self.canvas)
        layout.addWidget(self.button)
        self.setLayout(layout)

    def plot(self):
        ''' plot some random stuff '''
        # random data
        data = [random.random() for i in range(10)]

        # create an axis
        ax = self.figure.add_subplot(111)

        # discards the old graph
        ax.hold(False)

        # plot data
        ax.plot(data, '*-')

        # refresh canvas
        self.canvas.draw()
开发者ID:saknayo,项目名称:sspainter,代码行数:44,代码来源:test.py

示例13: detach_plot

# 需要导入模块: from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg import draw [as 别名]
    def detach_plot(self):
        new_window = QtWidgets.QMainWindow(self)
        new_window.setWindowTitle('Graphique détaché')

        frame = QtWidgets.QFrame(new_window)

        canvas = FigureCanvas(self.figure)
        canvas.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
        canvas.updateGeometry()
        canvas.draw()

        toolbar = NavigationToolbar(canvas, frame)

        layout = QtWidgets.QVBoxLayout(frame)
        layout.addWidget(canvas, 1)
        layout.addWidget(toolbar, 0)

        new_window.setCentralWidget(frame)
        new_window.show()

        return new_window
开发者ID:AlexandreDecan,项目名称:pytbul,代码行数:23,代码来源:gui.py

示例14: SensorWidget

# 需要导入模块: from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg import draw [as 别名]
class SensorWidget():
    # ToDo: Add signal to this object and emit value each time new value
    # is taken from queue
    def __init__(self, parent=None):
        self.figure, self.axes = plt.subplots()
        self.x_axis = []
        self.y_values = []
        self.sensor_plot_queue = Queue(maxsize=N_POINTS_ON_PLOT)

        self.compute_initial_figure()
        self.canvas = FigureCanvas(self.figure)
        self.canvas.setParent(parent)

        self.timer = QtCore.QTimer()
        self.timer.timeout.connect(self.update_figure)
        self.timer.start(50)

    def compute_initial_figure(self):
        self.axes.plot(self.y_values)

    def feed_value(self, value):
        self.sensor_plot_queue.put(value)

    def update_figure(self):
        self.axes.cla()
        # ToDo: Need to add lock here and iterate through all elements
        if not self.sensor_plot_queue.empty():
            self.y_values.append(self.sensor_plot_queue.get())
        if len(self.y_values) > N_POINTS_ON_PLOT:
            self.y_values.pop(0)
            self.x_axis = [x + 1 for x in self.x_axis]
        else:
            self.axes.set_xlim(0, N_POINTS_ON_PLOT)
            while len(self.x_axis) < len(self.y_values):
                self.x_axis.append(len(self.y_values))
        self.axes.plot(self.x_axis, self.y_values, ".")
        self.axes.plot(self.x_axis, self.y_values, "-")
        logging.debug("Drawing new plot")
        self.canvas.draw()
开发者ID:Qrlet,项目名称:Power_Inverter,代码行数:41,代码来源:gui.py

示例15: fcHistogram

# 需要导入模块: from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg import draw [as 别名]
class fcHistogram(QDialog, Ui_histwin):
    def __init__(self, parent=None):
        super(fcHistogram, self).__init__(parent)
        self.setupUi(self)
        fig1 = Figure()
        self.canvas = FigureCanvas(fig1)
        self.histogram.addWidget(self.canvas)
        self.plot = fig1.add_subplot(111)
        self.plot.set_ylim([0, 5000])
        self.plot.set_xlim([0, 256])
        self.canvas.draw()
        
    def setupThreadingUpdates(self, imgthread):
        #set up connections to UI update from imgthread
        imgthread.displayWashoutsSig.connect(self.displayWashouts)
        imgthread.plotHistogramSig.connect(self.plotHistogram)

    def displayWashouts(self, over, px, avg): #in hindsight, is this really useful?
        logging.debug("DisplayWashouts Called")
        logging.debug(over[1])
        logging.debug(avg)
        logging.debug(px)
        self.pctOverB.setText(adj_for_size(over[0], px))
        self.pctOverG.setText(adj_for_size(over[1], px))
        self.pctOverR.setText(adj_for_size(over[2], px))
        self.pctUnder.setText(adj_for_size(over[3], px))
        self.pctAvg.setText(str(avg))

    def plotHistogram(self, colorhists, grayhist, px):
        global colors
        logging.debug("plotHistogram Called")
        self.plot.cla()
        self.plot.fill(grayhist, color="gray")
        for i,col in enumerate(colors):
            self.plot.plot(colorhists[i],color = col)
        self.plot.set_ylim([0,px/128])
        self.plot.set_xlim([0,256])
        self.canvas.draw()
开发者ID:jphfilm,项目名称:rpi-film-capture,代码行数:40,代码来源:fcDialog.py


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