|
From: Dan K. <ka...@tx...> - 2006-11-09 15:40:54
|
I did my best to search the examples, mailing list, etc. but was surprised
that I didn't even find this question asked, let alone answered.
My basic question: Is it possible to remove a data series from a matplotlib
plot?
Longer question:
I'm using matplotlib to generate graph images for an interactive web site.
Through the web site, the user can create a plot and add data series to it.
I'd also like the user to be able to remove a data series. At the moment, I
am accomplishing this by clearing the plot and replotting all the data
series except of course for the one to be removed. This seems inefficient.
So something like:
fig = Figure()
ax = fig.add_subplot(111)
series1 = ax.plot(<some plot parameters here>)
series2 = ax.plot(<some plot parameters here>)
series3 = ax.plot(<some plot parameters here>)
And now I want to remove series2 from the plot.
Is this possible? If it is, can anyone point me to the relevant part of the
user's guide/class library? Or is the best approach to clear the plot and
replot 1 and 3 (and reset all the axes, legends, etc.)
I apologize if this is a FAQ, but as I said, my search for it came up empty.
Thanks,
-Dan
------
ka...@tx...
|
|
From: Fernando P. <fpe...@gm...> - 2006-11-09 16:45:59
|
Hi Dan, On 11/9/06, Dan Karipides <ka...@tx...> wrote: > I did my best to search the examples, mailing list, etc. but was surprised > that I didn't even find this question asked, let alone answered. Coincidentally it was asked just yesterday by Andrea Gavana, but you may have missed it in your search (it may have crossed with your posting time). > My basic question: Is it possible to remove a data series from a matplotlib > plot? Here is a little self-contained example you can try (N==numpy, P=pylab): In [24]: x = N.arange(10) In [25]: fig = P.figure() In [26]: ax = fig.add_subplot(111) In [27]: ax.plot(x) Out[27]: [<matplotlib.lines.Line2D instance at 0x427ce7ec>] In [28]: ax.plot(x+10) Out[28]: [<matplotlib.lines.Line2D instance at 0x427ce88c>] In [29]: ax.plot(x+20) Out[29]: [<matplotlib.lines.Line2D instance at 0x427ce9ac>] In [30]: P.show() In [31]: ax.lines Out[31]: [<matplotlib.lines.Line2D instance at 0x427ce7ec>, <matplotlib.lines.Line2D instance at 0x427ce88c>, <matplotlib.lines.Line2D instance at 0x427ce9ac>] In [32]: del ax.lines[1] In [33]: P.show() This makes the middle line disappear from the plot. Regards, f |
|
From: Dan K. <ka...@tx...> - 2006-11-09 17:05:51
|
Fernando, Thanks, this is exactly what I need. BTW, I think I missed it in the search because the archive here: http://sourceforge.net/mailarchive/forum.php?forum_id=33405 doesn't show anything more recent that 10/02/2006. I'm not sure why this is. Thanks again, -Dan ----- ka...@tx... -----Original Message----- From: Fernando Perez [mailto:fpe...@gm...] Sent: Thursday, November 09, 2006 9:46 AM To: Dan Karipides Cc: mat...@li... Subject: Re: [Matplotlib-users] Removing a data series Hi Dan, On 11/9/06, Dan Karipides <ka...@tx...> wrote: > I did my best to search the examples, mailing list, etc. but was surprised > that I didn't even find this question asked, let alone answered. Coincidentally it was asked just yesterday by Andrea Gavana, but you may have missed it in your search (it may have crossed with your posting time). > My basic question: Is it possible to remove a data series from a matplotlib > plot? Here is a little self-contained example you can try (N==numpy, P=pylab): In [24]: x = N.arange(10) In [25]: fig = P.figure() In [26]: ax = fig.add_subplot(111) In [27]: ax.plot(x) Out[27]: [<matplotlib.lines.Line2D instance at 0x427ce7ec>] In [28]: ax.plot(x+10) Out[28]: [<matplotlib.lines.Line2D instance at 0x427ce88c>] In [29]: ax.plot(x+20) Out[29]: [<matplotlib.lines.Line2D instance at 0x427ce9ac>] In [30]: P.show() In [31]: ax.lines Out[31]: [<matplotlib.lines.Line2D instance at 0x427ce7ec>, <matplotlib.lines.Line2D instance at 0x427ce88c>, <matplotlib.lines.Line2D instance at 0x427ce9ac>] In [32]: del ax.lines[1] In [33]: P.show() This makes the middle line disappear from the plot. Regards, f |
|
From: Angus M. <am...@gm...> - 2006-11-09 21:39:35
|
On 10/11/06, Dan Karipides <ka...@tx...> wrote: > Fernando, > > Thanks, this is exactly what I need. > > BTW, I think I missed it in the search because the archive here: > > http://sourceforge.net/mailarchive/forum.php?forum_id=33405 > > doesn't show anything more recent that 10/02/2006. I'm not sure why this > is. > > Thanks again, > > -Dan > ----- > ka...@tx... > Since this is the third time I've seen this question pop up in a few months, I've put an entry in the wiki for it here (http://www.scipy.org/Cookbook/Matplotlib/DeletingAnExistingDataSeries). Fernando, I hope you don't mind me using your example on the page - it seemed the most thorough. A. -- AJC McMorland, PhD Student Physiology, University of Auckland |
|
From: Fernando P. <fpe...@gm...> - 2006-11-09 22:43:08
|
On 11/9/06, Angus McMorland <am...@gm...> wrote: > Since this is the third time I've seen this question pop up in a few > months, I've put an entry in the wiki for it here > (http://www.scipy.org/Cookbook/Matplotlib/DeletingAnExistingDataSeries). > Fernando, I hope you don't mind me using your example on the page - it > seemed the most thorough. How dare you! I'm going to sue for copyright theft! ;-) Thanks for the wiki entry, it's certainly a common need. Regards, f |
|
From: Pierre GM <pgm...@ma...> - 2006-11-09 16:47:12
|
> My basic question: Is it possible to remove a data series from a matplotlib > plot? A quite similar question was asked yesterday: The lines are stored in "ax.lines", by chronological order. If you want to delete the second one, just use del(ax.lines[1]), and redraw if needed. |