python - How to plot different graphs in different canvas in PyQt4 in a window? -
i trying code python3 gui plots 4 different graph in 4 respective layout : speed, height, coordinates , angle. right able draw figure in each respective layout. however, have no idea how plot different function each graph. used method randomly generate 10 points plot. when method called, plots same graph each 4 canvas.
so question **if there anyway plot different function respectively figure(one plot per graph)?**i pretty new python3 , grateful provided.
if possible, avoid using many subplots in figure since layout each figures exist already.
here current gui looks when call test method generates random points, can see the same graph plotted in each canvas
i mention, if adds constraints, code used plots graph update data coming thread.
and here's code:
pyqt4 import qtgui .flight_dataui import ui_dialog import matplotlib.pyplot plt matplotlib.backends.backend_qt4agg import figurecanvasqtagg figurecanvas matplotlib.backends.backend_qt4agg import navigationtoolbar2qt navigationtoolbar import random class flightdata(qtgui.qdialog, ui_dialog): def __init__(self, parent=none): qtgui.qdialog.__init__(self, parent) self.setupui(self) self.figure = plt.figure() # flightdata.figure = matplotlib.pyplot.figure() # creates figure widget self.name = figurecanvas(self.figure) self.speedgraph = figurecanvas(self.figure) self.heightgraph = figurecanvas(self.figure) self.mapgraph = figurecanvas(self.figure) self.anglegraph = figurecanvas(self.figure) # ------------------------------------------------------------- self.speedlayout.addwidget(self.speedgraph) # insert widget "speedgraph" in speedlayout self.heightlayout.addwidget(self.heightgraph) # insert widget "heightgraph" in heightlayout self.maplayout.addwidget(self.mapgraph) # insert widget "mapgraph" in maplayout self.anglelayout.addwidget(self.anglegraph) # insert widget "anglegraph" in anglelayout self.ax = self.figure.add_subplot(111) self.ax.hold(false) self.init_widgets() def init_widgets(self): self.analysebutton.clicked.connect(self.open_analysedata) self.draw_plot() def open_analysedata(self): self.done(2) # closes , delete dialog window et , return int 2 results in main_window.py def draw_plot(self): data = [random.random() in range(10)] self.ax.plot(data, '-*')
if embedding not import pyplot
, it's global state cause trouble. using same figure initialize 4 figurecanvas
objects. want like:
from matplotlib.figure import figure class flightdata(qtgui.qdialog, ui_dialog): def __init__(self, parent=none): qtgui.qdialog.__init__(self, parent) self.setupui(self) self.figs = {} self.canvas = {} self.axs = {} plot_names = ['speed', 'height', 'map', 'angle'] pn in plot_names: fig = figure() self.canvas[pn] = figurecanvas(fig) ax = fig.add_subplot(1, 1, 1) self.figs[pn] = fig self.axs[pn] = ax # ------------------------------------------------------------- self.speedlayout.addwidget(self.canvas['speed']) self.heightlayout.addwidget(self.canvas['height']) self.maplayout.addwidget(self.canvas['map']) self.anglelayout.addwidget(self.canvas['angle']) def draw_plot(self, target, data): self.axs[target].plot(data, '-*') self.canvas[target].draw_idle()
Comments
Post a Comment