Selectable vertical lines

Hello,

I am trying to add some vertical lines into a matplotlib figure axes.

The idea is to detect when the mouse passes over those lines in order to displace them following the mouse if the left button is pressed.

I need some help to know the simplest way to proceed. Currently I am looking into matplotlib.patches and considering to use a Polygon or a Rectangle but perhaps that solution is overkill for a simple line. Is there any example about how to do it? I am not using the pyplot interface but instantiating myself the Figure, the FigureCanvas and adding the axes to the figure.

Thanks for your time,

Armando

What about using axvline with the picker argument?
see http://matplotlib.org/users/event_handling.html

···

Le mardi 07 janvier 2014 à 15:19 +0100, "V. Armando Solé" a écrit :

Hello,

I am trying to add some vertical lines into a matplotlib figure axes.

The idea is to detect when the mouse passes over those lines in order to
displace them following the mouse if the left button is pressed.

I need some help to know the simplest way to proceed. Currently I am
looking into matplotlib.patches and considering to use a Polygon or a
Rectangle but perhaps that solution is overkill for a simple line. Is
there any example about how to do it? I am not using the pyplot
interface but instantiating myself the Figure, the FigureCanvas and
adding the axes to the figure.

I think axvline is part of the pyplot interface that I am not using.

However your link is going to help me a lot. I thought picking was restricted to patches, and I had missed Line2D is an Artist too with the same capabilities.

Armando

···

On 07.01.2014 16:27, Fabrice Silva wrote:

Le mardi 07 janvier 2014 à 15:19 +0100, "V. Armando Solé" a écrit :

Hello,

I am trying to add some vertical lines into a matplotlib figure axes.

The idea is to detect when the mouse passes over those lines in order to
displace them following the mouse if the left button is pressed.

I need some help to know the simplest way to proceed. Currently I am
looking into matplotlib.patches and considering to use a Polygon or a
Rectangle but perhaps that solution is overkill for a simple line. Is
there any example about how to do it? I am not using the pyplot
interface but instantiating myself the Figure, the FigureCanvas and
adding the axes to the figure.

What about using axvline with the picker argument?
see http://matplotlib.org/users/event_handling.html

axvline is a pyplot function, but it is also a method of the Axes class.
So if you have an Axes in your Figure, everything is ok
http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.axvline

regards

···

Le mardi 07 janvier 2014 à 17:57 +0100, V. Armando Sole a écrit :

> What about using axvline with the picker argument?
> see http://matplotlib.org/users/event_handling.html
>

I think axvline is part of the pyplot interface that I am not using.

However your link is going to help me a lot. I thought picking was
restricted to patches, and I had missed Line2D is an Artist too with the
same capabilities.

Even better :slight_smile:

Thanks a lot,

Armando

···

On 07.01.2014 18:18, Fabrice Silva wrote:

Le mardi 07 janvier 2014 à 17:57 +0100, V. Armando Sole a écrit :

> What about using axvline with the picker argument?
> see http://matplotlib.org/users/event_handling.html
>

I think axvline is part of the pyplot interface that I am not using.

However your link is going to help me a lot. I thought picking was
restricted to patches, and I had missed Line2D is an Artist too with the
same capabilities.

axvline is a pyplot function, but it is also a method of the Axes class.
So if you have an Axes in your Figure, everything is ok
http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.axvline