How to get multiple plots in one plot window inside qt application

10,012 views
Skip to first unread message

Timo77

unread,
Apr 29, 2013, 11:51:00 AM4/29/13
to pyqt...@googlegroups.com
I have made a UI using qt designer that has multiple tabbed windows within the main window.  Inside one of these tabs is a graph of data.  Inside another is a spreadsheet of the data points, inside another is a textview that shows all the stats.  All of this works fine right now.  What I want to do (and can't seem to figure out) is to make multiple graphs inside the one plot widget in my graph tab (I attached a sample of what I'd like to see).  I am new to qt and GUI designing, so any help would be appreciated.  Below is the relevant code:
 
from __future__ import division

import sys

from lablayout2 import *

from PyQt4.QtGui import *

from PyQt4.QtCore import *

import pyqtgraph as pg

from pyqtgraph.Point import Point

from pyqtgraph.Qt import QtGui, QtCore

import numpy as np

import gc

import random

import serial

import re

import csv

import matplotlib as ml


class MyForm(QtGui.QMainWindow):

plotUpdating = 0

i=0

data=[]

nl=0

nq=0

s = serial.Serial('COM3',9600,timeout=1)

buffer = ''

def __init__(self,parent=None):

QtGui.QWidget.__init__(self,parent)

self.ui = Ui_MainWindow()

self.ui.setupUi(self)

self.graph = self.ui.graphicsView.getPlotItem()

#self.graph2 = self.ui.graphicsView.getPlotItem()

self.graph.showGrid(x=True, y=True, alpha=None)

self.graph.addLegend()

self.updatePlot()

self.timer = QtCore.QTimer(self)

self.connect(self.ui.actionStartData, QtCore.SIGNAL('triggered()')

,self.startData)

self.connect(self.ui.actionStopData, QtCore.SIGNAL('triggered()')

,self.stopData)

self.connect(self.ui.actionExit_Application,QtCore.SIGNAL('triggered()')

,self.quitApplication)

self.connect(self.ui.actionOpen,QtCore.SIGNAL('triggered()')

,self.openFile)

self.connect(self.ui.actionSave,QtCore.SIGNAL('triggered()')

,self.saveFile)

self.connect(self.ui.actionQuadratic, QtCore.SIGNAL('triggered()')

,self.quadraticFit)

self.connect(self.ui.actionLinear, QtCore.SIGNAL('changed()')

,self.linearFit)

self.connect(self.ui.action3rd_order, QtCore.SIGNAL('triggered()')

,self.thirdFit)

self.connect(self.ui.action4th_order, QtCore.SIGNAL('triggered()')

,self.fourthFit)

self.connect(self.ui.action5th_order, QtCore.SIGNAL('triggered()')

,self.fifthFit)

self.connect(self.ui.statisticsButton, QtCore.SIGNAL('clicked()')

,self.updateStatistics)

self.graph.scene().sigMouseMoved.connect(self.mouseMoved)

self.ui.textBrowser.append('Statistics')

# Used for the crosshairs in the plot...

self.vLine = pg.InfiniteLine(angle=90, movable=False)

self.hLine = pg.InfiniteLine(angle=0, movable=False)

       

self.proxy = pg.SignalProxy(self.graph.scene().sigMouseMoved, rateLimit=10

, slot=self.mouseMoved)

           

 
 
sampleMultiPlots.png

Luke Campagnola

unread,
Apr 29, 2013, 12:00:23 PM4/29/13
to pyqt...@googlegroups.com
On Mon, Apr 29, 2013 at 11:51 AM, Timo77 <timob...@gmail.com> wrote:
I have made a UI using qt designer that has multiple tabbed windows within the main window.  Inside one of these tabs is a graph of data.  Inside another is a spreadsheet of the data points, inside another is a textview that shows all the stats.  All of this works fine right now.  What I want to do (and can't seem to figure out) is to make multiple graphs inside the one plot widget in my graph tab (I attached a sample of what I'd like to see). 

PlotWidget, by its definition, only contains a single plot area. If you use GraphicsLayoutWidget instead, then you can add as many plots to that as needed. See the example code for the screenshot you posted: http://bazaar.launchpad.net/~luke-campagnola/pyqtgraph/main/view/head:/examples/Plotting.py  (note that the example uses GraphicsWindow; you can use GraphicsLayoutWidget in exactly the same way).

If you want to be able to lay out the plots from designer, then you'll instead need to create multiple PlotWidgets inside a grid layout.


Luke
 

Timo77

unread,
Apr 29, 2013, 12:06:46 PM4/29/13
to pyqt...@googlegroups.com
Thanks for the quick reply.  I will try what you suggested.  I had tried the graphicsWindow in the example and could not get it to work.  I will use the GraphicsLayoutWidget now and see how it goes.  I'll keep you posted!
Timo

Timo77

unread,
Apr 29, 2013, 1:03:06 PM4/29/13
to pyqt...@googlegroups.com
Luke,
I got it working.  Thanks so much!
Timo

Timo77

unread,
Apr 29, 2013, 1:10:30 PM4/29/13
to pyqt...@googlegroups.com
Luke,
One more question about my application:  I have the ability to do curve fitting to the data within my graphs.  The curve fits show up, and the equation for the curve fit shows up in the legend.  That part works well right now.  What doesn't work well is that I want to be able to toggle the fits on and off.  I noticed that there is a method to add an entry to a legend, but not to delete one.  Is there a tidy way to do this?
Timo
Reply all
Reply to author
Forward
0 new messages