where is line after remove?

Hi

Working on my little experiment (backend with edition capabilities https://github.com/fariza/MPL-Experimental-Backend)

I want to turn visibility on and off for lines.

I can not use the visible property, using it the autolimits “relim” keeps considering the lines as being there.
As consequence the limits are wrong (if we think only on the visible lines).

So I resorted to remove the line from its axes by line.remove()

The question is:
If I do not want to use another variable to keep track of this line, how can I find it again from the figure instance (or somewhere else)?
get_children gets me nowhere… or maybe?

···

#################

import matplotlib.pylab as plt

fig = plt.figure()
ax = fig.add_subplot(111)
line = ax.plot(range(100))

print line[0] in ax.lines
line[0].remove()
print line[0] in ax.lines
plt.show()
#################

Thanks
Federico


Y yo que culpa tengo de que ellas se crean todo lo que yo les digo?

– Antonio Alducin –

[...]
I want to turn visibility on and off for lines.
I can not use the visible property, using it the autolimits "relim" keeps
considering the lines as being there.
As consequence the limits are wrong (if we think only on the visible lines).

I faced this some time ago and my workaround was writing my own
(simplified) version of relim, if memory serves. But this may not fit
your needs here. Maybe a better solution is modify relim upstream so
it can take visibility into account (maybe using a new keyword). Just
a quick thought.

So I resorted to remove the line from its axes by line.remove()

The question is:
If I do not want to use another variable to keep track of this line, how can
I find it again from the figure instance (or somewhere else)?
get_children gets me nowhere.... or maybe?

I don't think matplotlib keeps a reference to a line object after you
remove it from the axes. If I'm right and you want to follow that path
you'll need to track it yourself.

Regards

Goyo

···

El día 13 de marzo de 2012 00:25, Federico Ariza <ariza.federico@...287...> escribió:

Hi

That is exactly what I am doing, but I thought it was kept somewhere.

I like the idea of upstream modification of relim.

Thanks
Federico

···

On Tue, Mar 13, 2012 at 2:13 PM, Goyo <goyodiaz@…287…> wrote:

El día 13 de marzo de 2012 00:25, Federico Ariza > > <ariza.federico@…287…> escribió:

[…]
I want to turn visibility on and off for lines.

I can not use the visible property, using it the autolimits “relim” keeps

considering the lines as being there.

As consequence the limits are wrong (if we think only on the visible lines).

I faced this some time ago and my workaround was writing my own

(simplified) version of relim, if memory serves. But this may not fit

your needs here. Maybe a better solution is modify relim upstream so

it can take visibility into account (maybe using a new keyword). Just

a quick thought.

So I resorted to remove the line from its axes by line.remove()

The question is:

If I do not want to use another variable to keep track of this line, how can

I find it again from the figure instance (or somewhere else)?

get_children gets me nowhere… or maybe?

I don’t think matplotlib keeps a reference to a line object after you

remove it from the axes. If I’m right and you want to follow that path

you’ll need to track it yourself.

Regards

Goyo


Y yo que culpa tengo de que ellas se crean todo lo que yo les digo?

– Antonio Alducin –

Federico,

Why would you think it is kept somewhere? The method is called “remove”, after all. I am curious because I want to know if improvements are needed to the documentation.

As for relim(), I am thinking the autoscaling system needs another revamp. I have ran into subtle issues with data limits that could not be easily fixed in the current design.

Everything plottable should have a get/set for x and y data, as well as get/set for "data" (which may or may not be the same as the get/set for y. Note that there might be some confusion regarding scalar mappables. I think this might be the source of confusion where some collections have set_data() while others have set_array().

Also, not all objects, for some reason, implement remove(), or something else messed up that I am not clear about.

Cheers!
Ben Root

···

On Tue, Mar 13, 2012 at 1:20 PM, Federico Ariza <ariza.federico@…287…> wrote:

Hi

That is exactly what I am doing, but I thought it was kept somewhere.

I like the idea of upstream modification of relim.

Thanks
Federico

Ben

Yest It is called remove but not destroy :wink:
Given that the relim takes in count the invisible lines, I thougth it was planned that you could “remove” and “add” the lines from its axes.

Thanks
Federico

···

On Tue, Mar 13, 2012 at 2:44 PM, Benjamin Root <ben.root@…1304…> wrote:

On Tue, Mar 13, 2012 at 1:20 PM, Federico Ariza <ariza.federico@…287…> wrote:

Hi

That is exactly what I am doing, but I thought it was kept somewhere.

I like the idea of upstream modification of relim.

Thanks
Federico

Federico,

Why would you think it is kept somewhere? The method is called “remove”, after all. I am curious because I want to know if improvements are needed to the documentation.

As for relim(), I am thinking the autoscaling system needs another revamp. I have ran into subtle issues with data limits that could not be easily fixed in the current design.

Everything plottable should have a get/set for x and y data, as well as get/set for "data" (which may or may not be the same as the get/set for y. Note that there might be some confusion regarding scalar mappables. I think this might be the source of confusion where some collections have set_data() while others have set_array().

Also, not all objects, for some reason, implement remove(), or something else messed up that I am not clear about.

Cheers!
Ben Root


Y yo que culpa tengo de que ellas se crean todo lo que yo les digo?

– Antonio Alducin –

It would be trivial to add a kwarg to relim:

include_invisible=True

which defaults to the current behavior.

def relim(self, include_invisible=True):

“”"

Recompute the data

limits based on current artists. If you want to exclude

invisible artists from the calculation, set

include_invisible=False

At present, :class:~matplotlib.collections.Collection

instances are not supported.

“”"

Collections are deliberately not supported (yet); see

the TODO note in artists.py.

self.dataLim.ignore(True)

self.ignore_existing_data_limits = True

for line in self.lines:

    if include_invisible or line.get_visible():

self._update_line_limits(line)

for p in self.patches:

    if include_invisible or p.get_visible():

self._update_patch_limits(p)

But include_invisible isn’t the most intuitive name…

JDH

···

On Tue, Mar 13, 2012 at 1:20 PM, Federico Ariza <ariza.federico@…287…> wrote:

Hi

That is exactly what I am doing, but I thought it was kept somewhere.

I like the idea of upstream modification of relim.

    Hi

    That is exactly what I am doing, but I thought it was kept somewhere.

    I like the idea of upstream modification of relim.

It would be trivial to add a kwarg to relim:

include_invisible=True

which defaults to the current behavior.
     def relim(self, include_invisible=True):
"""
         Recompute the data
         limits based on current artists. If you want to exclude
         invisible artists from the calculation, set
         `include_invisible=False`

         At present, :class:`~matplotlib.collections.Collection`
         instances are not supported.
"""
         # Collections are deliberately not supported (yet); see
         # the TODO note in artists.py.
         self.dataLim.ignore(True)
         self.ignore_existing_data_limits = True
         for line in self.lines:
    if include_invisible or line.get_visible():
                 self._update_line_limits(line)

         for p in self.patches:
    if include_invisible or p.get_visible():
                 self._update_patch_limits(p)

But include_invisible isn't the most intuitive name...

visible_only=False is shorter.

Eric

···

On 03/13/2012 09:17 AM, John Hunter wrote:

On Tue, Mar 13, 2012 at 1:20 PM, Federico Ariza > <ariza.federico@...287... <mailto:ariza.federico@…287…>> wrote:

JDH

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Hello

Finally (after long time) I managed to get time and courage to make my first PR with this little modification
https://github.com/matplotlib/matplotlib/pull/2417

Federico

···

On Tue, Mar 13, 2012 at 3:17 PM, John Hunter <jdh2358@…287…> wrote:

On Tue, Mar 13, 2012 at 1:20 PM, Federico Ariza <ariza.federico@…287…> wrote:

Hi

That is exactly what I am doing, but I thought it was kept somewhere.

I like the idea of upstream modification of relim.

It would be trivial to add a kwarg to relim:

include_invisible=True

which defaults to the current behavior.

def relim(self, include_invisible=True):

“”"

Recompute the data

limits based on current artists. If you want to exclude

invisible artists from the calculation, set

include_invisible=False

At present, :class:~matplotlib.collections.Collection

instances are not supported.

“”"

Collections are deliberately not supported (yet); see

the TODO note in artists.py.

self.dataLim.ignore(True)

self.ignore_existing_data_limits = True

for line in self.lines:

  if include_invisible or line.get_visible():

self._update_line_limits(line)

for p in self.patches:

  if include_invisible or p.get_visible():

self._update_patch_limits(p)

But include_invisible isn’t the most intuitive name…

JDH


Y yo que culpa tengo de que ellas se crean todo lo que yo les digo?

– Antonio Alducin –