re move / delete arrow / annotate, how to?

Hi,

I'm trying to remove or delete an annotate arrow but I'm unsuccessful. Can
some please help? Thanks.

I tried the [artist].remove() but that will not work with arrows or annotate
objects...

Here is some example code, please add in the code I need if you can:

import numpy as np
import matplotlib.pyplot as plt

t = np.arange(0, np.pi*2, 0.01)
x = np.sin(2*np.pi*t)
fig = plt.figure()
myplot = ax.plot(t, x, 'b')

arrow = ax. annotate('my arrow', xy=(3, -0.5), xycoords='data',
                            horizontalalignment='center',
                            verticalalignment='center',
                            color='red', alpha=0.5,
                            xytext=(0, -2), textcoords='offset points',
                            arrowprops=dict(facecolor='red', frac=0.4,
shrink = 0.05, alpha=0.5, width=2, headwidth=5),
                            )

#Code to remove arrow...
# arrow.remove() #this does not work...

plt.show()

···

-----
Krishna Adrianto Pribadi
Test Engineer
Harley-Davidson Motor Co.
Talladega Test Facility
Vehicle Test Stands

View this message in context: http://old.nabble.com/remove---delete-arrow---annotate%2C-how-to--tp28451836p28451836.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

You can accomplish it by:

ax.texts.remove(arrow)

I'd still like to know why this exception gets raised:

NotImplementedError Traceback (most recent call last)

/home/rmay/<ipython console> in <module>()

/home/rmay/.local/lib/python2.6/site-packages/matplotlib/artist.pyc in
remove(self)
    123 self._remove_method(self)
    124 else:
--> 125 raise NotImplementedError('cannot remove artist')
    126 # TODO: the fix for the collections relim problem is to move the

    127 # limits calculation into the artist itself, including
the property

NotImplementedError: cannot remove artist

JJ, thoughts?

Ryan

···

On Tue, May 4, 2010 at 2:09 PM, KrishnaPribadi <Krishna.Pribadi@...3019...> wrote:

I'm trying to remove or delete an annotate arrow but I'm unsuccessful. Can
some please help? Thanks.

I tried the [artist].remove() but that will not work with arrows or annotate
objects...

Here is some example code, please add in the code I need if you can:

import numpy as np
import matplotlib.pyplot as plt

t = np.arange(0, np.pi*2, 0.01)
x = np.sin(2*np.pi*t)
fig = plt.figure()
myplot = ax.plot(t, x, 'b')

arrow = ax. annotate('my arrow', xy=(3, -0.5), xycoords='data',
horizontalalignment='center',
verticalalignment='center',
color='red', alpha=0.5,
xytext=(0, -2), textcoords='offset points',
arrowprops=dict(facecolor='red', frac=0.4,
shrink = 0.05, alpha=0.5, width=2, headwidth=5),
)

#Code to remove arrow...
# arrow.remove() #this does not work...

plt.show()

--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

Fixed in r8295.

Axes.annotate was not setting the _remove_method attribute.
Regards,

-JJ

···

On Tue, May 4, 2010 at 3:15 PM, Ryan May <rmay31@...287...> wrote:

On Tue, May 4, 2010 at 2:09 PM, KrishnaPribadi > <Krishna.Pribadi@...3019...> wrote:

I'm trying to remove or delete an annotate arrow but I'm unsuccessful. Can
some please help? Thanks.

I tried the [artist].remove() but that will not work with arrows or annotate
objects...

Here is some example code, please add in the code I need if you can:

import numpy as np
import matplotlib.pyplot as plt

t = np.arange(0, np.pi*2, 0.01)
x = np.sin(2*np.pi*t)
fig = plt.figure()
myplot = ax.plot(t, x, 'b')

arrow = ax. annotate('my arrow', xy=(3, -0.5), xycoords='data',
horizontalalignment='center',
verticalalignment='center',
color='red', alpha=0.5,
xytext=(0, -2), textcoords='offset points',
arrowprops=dict(facecolor='red', frac=0.4,
shrink = 0.05, alpha=0.5, width=2, headwidth=5),
)

#Code to remove arrow...
# arrow.remove() #this does not work...

plt.show()

You can accomplish it by:

ax.texts.remove(arrow)

I'd still like to know why this exception gets raised:

NotImplementedError Traceback (most recent call last)

/home/rmay/<ipython console> in <module>()

/home/rmay/.local/lib/python2.6/site-packages/matplotlib/artist.pyc in
remove(self)
123 self._remove_method(self)
124 else:
--> 125 raise NotImplementedError('cannot remove artist')
126 # TODO: the fix for the collections relim problem is to move the

127 # limits calculation into the artist itself, including
the property

NotImplementedError: cannot remove artist

JJ, thoughts?

Ryan

--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

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

Ryan May-3 wrote:

You can accomplish it by:

ax.texts.remove(arrow)

I'd still like to know why this exception gets raised:

NotImplementedError Traceback (most recent call
last)

/home/rmay/<ipython console> in <module>()

/home/rmay/.local/lib/python2.6/site-packages/matplotlib/artist.pyc in
remove(self)
    123 self._remove_method(self)
    124 else:
--> 125 raise NotImplementedError('cannot remove artist')
    126 # TODO: the fix for the collections relim problem is to
move the

    127 # limits calculation into the artist itself, including
the property

NotImplementedError: cannot remove artist

JJ, thoughts?

Ryan

--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

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

Ryan,
I implemented this code fine and NEVER got any raised exceptions... Maybe
you did something else wrong?

···

-----
Krishna Adrianto Pribadi
Test Engineer
Harley-Davidson Motor Co.
Talladega Test Facility
Vehicle Test Stands
--
View this message in context: http://old.nabble.com/remove---delete-arrow---annotate%2C-how-to--tp28451836p28460643.html
Sent from the matplotlib - users mailing list archive at Nabble.com.