Remove a single plot from a group of plots in the same PlotItem

4,213 views
Skip to first unread message

Todd Batzler

unread,
Jun 2, 2015, 7:46:42 AM6/2/15
to pyqt...@googlegroups.com
From examples\Plotting.py
<snip>
p2 = win.addPlot(title="Multiple curves")

p2.plot(np.random.normal(size=100), pen=(255,0,0), name="Red curve")

p2.plot(np.random.normal(size=110)+5, pen=(0,255,0), name="Blue curve")

p2.plot(np.random.normal(size=120)+10, pen=(0,0,255), name="Green curve")

<snip>


Can someone please demonstrate the procedure to now remove one of these curves?

Everything I've tried, except for clear() which removes everything in the plot window, either throws and attribute exception or does nothing.

Thanks.


Thanks.


anonymou...@gmail.com

unread,
Jun 2, 2015, 11:32:54 PM6/2/15
to pyqt...@googlegroups.com
p2 = win.addPlot(title="Multiple curves")

c1
= p2.plot(np.random.normal(size=100), pen=(255,0,0), name="Red curve")
c2
= p2.plot(np.random.normal(size=110)+5, pen=(0,255,0), name="Blue curve")
c3
= p2.plot(np.random.normal(size=120)+10, pen=(0,0,255), name="Green curve")

print type( p2 )  #<class 'pyqtgraph.graphicsItems.PlotItem.PlotItem.PlotItem'>
print type( c1 )  #<class 'pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem'>

#So each curve is a PlotDataItem (PlotDataItem.py) with its own clear() method so

c1
.clear()



anonymou...@gmail.com

unread,
Jun 2, 2015, 11:53:56 PM6/2/15
to pyqt...@googlegroups.com
#OOPS, I just noticed that some_curve.clear() only clears the data content
#and
 
PlotItem.py has a removeItem() method to remove the curves
entirely from the viewbox so:

p2
.removeItem( c2 )



Todd Batzler

unread,
Jun 3, 2015, 7:41:27 AM6/3/15
to pyqt...@googlegroups.com
Thanks.  I was just returning to the forum to post something similar when I figured it out yesterday.  My 'hurdle' was understanding that a PlotItem contains PlotDataItems and then how to reference a specific data item.  Found a bread crumb in a similar post talking about problems with PlotItem indices and then it 'clicked'.

Just for fun I also found you can add the plot data back to the PlotItem using the addItem method:
p2.addItem( c2 )
Reply all
Reply to author
Forward
0 new messages