Discussion:
[pyqtgraph] Remove a single plot from a group of plots in the same PlotItem
Todd Batzler
2015-06-02 11:46:42 UTC
Permalink
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.
--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/149d32f1-f3b4-4ba2-9989-235d44e705e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
a***@gmail.com
2015-06-03 03:32:54 UTC
Permalink
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()
--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/6879e097-2262-41d2-abf7-625d5cbc9841%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
a***@gmail.com
2015-06-03 03:53:56 UTC
Permalink
#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 )
--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/826852ec-248c-4aa7-be57-bf4749bcf962%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Todd Batzler
2015-06-03 11:41:27 UTC
Permalink
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 )
Post by a***@gmail.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
p2.removeItem( c2 )
--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/585d3ba2-80a9-4a08-ab23-af98bab09a4d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...