Hiding data via legend

Hello,

I was wondering if it is possible to hide some data on figures using a say right click option to any of the legend entry and make it temporarily hidden/visible to better analyse the rest of the data?

Check this screenshot for example:

http://img25.imageshack.us/img25/9427/datahiding.png

The red data clutters the rest of the figure, and I would like to be able to hide it temporarily so that I can investigate the other two relations more easily.

Any ideas? or alternative solutions?

Thanks.

···


Gökhan

For this particular data set you might try simply using a log-scaled Y-axis.
As to the larger question of interactively adding/removing plot elements,
take a look at Enthought's Chaco toolkit. I think most people would agree
that its plotting features are not as rich as mpl, but with respect to
customizing interaction with graphical elements, it seems like the best path
out there. See
http://code.enthought.com/projects/chaco/docs/html/user_manual/faq.html

Josh

Gökhan SEVER-2 wrote:

···

Hello,

I was wondering if it is possible to hide some data on figures using a say
right click option to any of the legend entry and make it temporarily
hidden/visible to better analyse the rest of the data?

Check this screenshot for example:

http://img25.imageshack.us/img25/9427/datahiding.png

The red data clutters the rest of the figure, and I would like to be able
to
hide it temporarily so that I can investigate the other two relations more
easily.

Any ideas? or alternative solutions?

Thanks.

--
Gökhan

-----
Josh Hemann
Statistical Advisor
http://www.vni.com/ Visual Numerics
jhemann@...1899... | P 720.407.4214 | F 720.407.4199

--
View this message in context: http://www.nabble.com/Hiding-data-via-legend-tp24802219p24811505.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

It's a nice idea, and should be doable with the pick interface we have
for all mpl artists. Unfortunately, there were a few problems in the
legend implementation which blocked the pick events from hitting the
proxy lines they contained. I just made a few changes to mpl svn HEAD
to support this, and added a new example.

  examples/event_handling/legend_picking.py

which I'll include below. JJ could you review the changes to legend.py?

Instructions for checking out svn are at::

  http://matplotlib.sourceforge.net/faq/installing_faq.html#install-from-svn

Here is the example:

"""
Enable picking on the legend to toggle the legended line on and off
"""
import numpy as np
import matplotlib.pyplot as plt

t = np.arange(0.0, 0.2, 0.1)
y1 = 2*np.sin(2*np.pi*t)
y2 = 4*np.sin(2*np.pi*2*t)

fig = plt.figure()
ax = fig.add_subplot(111)

line1, = ax.plot(t, y1, lw=2, color='red', label='1 hz')
line2, = ax.plot(t, y2, lw=2, color='blue', label='2 hz')

leg = ax.legend(loc='upper left', fancybox=True, shadow=True)
leg.get_frame().set_alpha(0.4)

lines = [line1, line2]
lined = dict()
for legline, realine in zip(leg.get_lines(), lines):
    legline.set_picker(5) # 5 pts tolerance
    lined[legline] = realine

def onpick(event):
    legline = event.artist
    realline = lined[legline]
    vis = realline.get_visible()
    realline.set_visible(not vis)
    fig.canvas.draw()

fig.canvas.mpl_connect('pick_event', onpick)

plt.show()

···

On Mon, Aug 3, 2009 at 11:38 PM, Gökhan Sever<gokhansever@...287...> wrote:

Hello,

I was wondering if it is possible to hide some data on figures using a say
right click option to any of the legend entry and make it temporarily
hidden/visible to better analyse the rest of the data?

Check this screenshot for example:

http://img25.imageshack.us/img25/9427/datahiding.png

The red data clutters the rest of the figure, and I would like to be able to
hide it temporarily so that I can investigate the other two relations more
easily.

Any ideas? or alternative solutions?

Awesome example. I tweaked it to change the alpha of the lines in the legend so that you know when you’ve turned off a line (making it more chaco-like).

Ryan

···

On Tue, Aug 4, 2009 at 11:50 AM, John Hunter <jdh2358@…83…287…> wrote:

On Mon, Aug 3, 2009 at 11:38 PM, Gökhan Sever<gokhansever@…287…> wrote:

Hello,

I was wondering if it is possible to hide some data on figures using a say

right click option to any of the legend entry and make it temporarily

hidden/visible to better analyse the rest of the data?

Check this screenshot for example:

http://img25.imageshack.us/img25/9427/datahiding.png

The red data clutters the rest of the figure, and I would like to be able to

hide it temporarily so that I can investigate the other two relations more

easily.

Any ideas? or alternative solutions?

It’s a nice idea, and should be doable with the pick interface we have

for all mpl artists. Unfortunately, there were a few problems in the

legend implementation which blocked the pick events from hitting the

proxy lines they contained. I just made a few changes to mpl svn HEAD

to support this, and added a new example.

examples/event_handling/legend_picking.py


Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

Excellent John. Right what I was seeking for. This will help me a lot to view and analyze my crowded plots.

Thanks also Ryan for the additional correction.

I have a little question on the code:

What is the purpose of using “commas” after line1 and line2 names?

I see a little change when I typed them in Ipython, however not exactly sure the real reasoning behind this.

In [4]: lines = ax.plot(t, y1, lw=2, color=‘red’, label=‘1 hz’)

In [5]: lines
Out[5]: [<matplotlib.lines.Line2D object at 0xabce76c>]

In [6]: lines, = ax.plot(t, y1, lw=2, color=‘red’, label=‘1 hz’)

In [7]: lines
Out[7]: <matplotlib.lines.Line2D object at 0xabceaec>

Thanks.

···

On Tue, Aug 4, 2009 at 11:50 AM, John Hunter <jdh2358@…83…287…> wrote:

On Mon, Aug 3, 2009 at 11:38 PM, Gökhan Sever<gokhansever@…287…> wrote:

Hello,

I was wondering if it is possible to hide some data on figures using a say

right click option to any of the legend entry and make it temporarily

hidden/visible to better analyse the rest of the data?

Check this screenshot for example:

http://img25.imageshack.us/img25/9427/datahiding.png

The red data clutters the rest of the figure, and I would like to be able to

hide it temporarily so that I can investigate the other two relations more

easily.

Any ideas? or alternative solutions?

It’s a nice idea, and should be doable with the pick interface we have

for all mpl artists. Unfortunately, there were a few problems in the

legend implementation which blocked the pick events from hitting the

proxy lines they contained. I just made a few changes to mpl svn HEAD

to support this, and added a new example.

examples/event_handling/legend_picking.py

which I’ll include below. JJ could you review the changes to legend.py?

Instructions for checking out svn are at::

http://matplotlib.sourceforge.net/faq/installing_faq.html#install-from-svn

Here is the example:

“”"

Enable picking on the legend to toggle the legended line on and off

“”"

import numpy as np

import matplotlib.pyplot as plt

t = np.arange(0.0, 0.2, 0.1)

y1 = 2np.sin(2np.pi*t)

y2 = 4np.sin(2np.pi2t)

fig = plt.figure()

ax = fig.add_subplot(111)

line1, = ax.plot(t, y1, lw=2, color=‘red’, label=‘1 hz’)

line2, = ax.plot(t, y2, lw=2, color=‘blue’, label=‘2 hz’)

leg = ax.legend(loc=‘upper left’, fancybox=True, shadow=True)

leg.get_frame().set_alpha(0.4)

lines = [line1, line2]

lined = dict()

for legline, realine in zip(leg.get_lines(), lines):

legline.set_picker(5)  # 5 pts tolerance

lined[legline] = realine

def onpick(event):

legline = event.artist

realline = lined[legline]

vis = realline.get_visible()

realline.set_visible(not vis)

fig.canvas.draw()

fig.canvas.mpl_connect(‘pick_event’, onpick)

plt.show()


Gökhan

Gökhan Sever wrote:

I see a little change when I typed them in Ipython, however not exactly sure the real reasoning behind this.

In [4]: lines = ax.plot(t, y1, lw=2, color='red', label='1 hz')

In [5]: lines
Out[5]: [<matplotlib.lines.Line2D object at 0xabce76c>]

Here the variable lines is a list with one element (a Line2D object).

In [6]: lines, = ax.plot(t, y1, lw=2, color='red', label='1 hz')

In [7]: lines
Out[7]: <matplotlib.lines.Line2D object at 0xabceaec>

Here lines is a Line2D object.

ax.plot always returns a list because it may plot more than one line. The choice of syntax for the caller of the function is just for convenience. One could just as easily do:

lines = ax.plot(t, y1, lw=2, color='red', label='1 hz')
line = lines[0]

Cheers,
Mike

···

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Yeah, it’s a nice little feature of python:

t = (1,2,3)
x,y,z = t #Now: x=1, y=2, z=3

Ryan

···

On Tue, Aug 4, 2009 at 2:27 PM, Michael Droettboom <mdroe@…878…86…> wrote:

Gökhan Sever wrote:

I see a little change when I typed them in Ipython, however not exactly sure the real reasoning behind this.

In [4]: lines = ax.plot(t, y1, lw=2, color=‘red’, label=‘1 hz’)

In [5]: lines

Out[5]: [<matplotlib.lines.Line2D object at 0xabce76c>]

Here the variable lines is a list with one element (a Line2D object).

In [6]: lines, = ax.plot(t, y1, lw=2, color=‘red’, label=‘1 hz’)

In [7]: lines

Out[7]: <matplotlib.lines.Line2D object at 0xabceaec>

Here lines is a Line2D object.

ax.plot always returns a list because it may plot more than one line. The choice of syntax for the caller of the function is just for convenience. One could just as easily do:


Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
Sent from Norman, Oklahoma, United States

Hello,

I was wondering if it is possible to hide some data on figures using a say
right click option to any of the legend entry and make it temporarily
hidden/visible to better analyse the rest of the data?

Check this screenshot for example:

http://img25.imageshack.us/img25/9427/datahiding.png

The red data clutters the rest of the figure, and I would like to be able to
hide it temporarily so that I can investigate the other two relations more
easily.

Any ideas? or alternative solutions?

It's a nice idea, and should be doable with the pick interface we have
for all mpl artists. Unfortunately, there were a few problems in the
legend implementation which blocked the pick events from hitting the
proxy lines they contained. I just made a few changes to mpl svn HEAD
to support this, and added a new example.

examples/event_handling/legend_picking.py

which I'll include below. JJ could you review the changes to legend.py?

John,

This looks good.
I guess I have overlooked the importance of setting the children properly.

Regards,

-JJ

···

On Tue, Aug 4, 2009 at 12:50 PM, John Hunter<jdh2358@...287...> wrote:

On Mon, Aug 3, 2009 at 11:38 PM, Gökhan Sever<gokhansever@...287...> wrote:

Instructions for checking out svn are at::

http://matplotlib.sourceforge.net/faq/installing_faq.html#install-from-svn

Here is the example:

"""
Enable picking on the legend to toggle the legended line on and off
"""
import numpy as np
import matplotlib.pyplot as plt

t = np.arange(0.0, 0.2, 0.1)
y1 = 2*np.sin(2*np.pi*t)
y2 = 4*np.sin(2*np.pi*2*t)

fig = plt.figure()
ax = fig.add_subplot(111)

line1, = ax.plot(t, y1, lw=2, color='red', label='1 hz')
line2, = ax.plot(t, y2, lw=2, color='blue', label='2 hz')

leg = ax.legend(loc='upper left', fancybox=True, shadow=True)
leg.get_frame().set_alpha(0.4)

lines = [line1, line2]
lined = dict()
for legline, realine in zip(leg.get_lines(), lines):
legline.set_picker(5) # 5 pts tolerance
lined[legline] = realine

def onpick(event):
legline = event.artist
realline = lined[legline]
vis = realline.get_visible()
realline.set_visible(not vis)
fig.canvas.draw()

fig.canvas.mpl_connect('pick_event', onpick)

plt.show()

Hi,

pickers work great to make matplotlib plots more interactive/general user
friendly.

On the subject of the legend_picker.py example, I was wondering if it was
possible to combine both a legend picker and a line picker in the same plot.

From what I gather they will both use the same onpick event callback.

So my question is : How do I discriminate between a pick on the legend from
a pick on a line ? The event.artist is a line2D in both cases.

John Hunter-4 wrote:

···

On Mon, Aug 3, 2009 at 11:38 PM, Gökhan Sever<gokhansever@...287...> > wrote:

Hello,

I was wondering if it is possible to hide some data on figures using a
say
right click option to any of the legend entry and make it temporarily
hidden/visible to better analyse the rest of the data?

Check this screenshot for example:

http://img25.imageshack.us/img25/9427/datahiding.png

The red data clutters the rest of the figure, and I would like to be able
to
hide it temporarily so that I can investigate the other two relations
more
easily.

Any ideas? or alternative solutions?

It's a nice idea, and should be doable with the pick interface we have
for all mpl artists. Unfortunately, there were a few problems in the
legend implementation which blocked the pick events from hitting the
proxy lines they contained. I just made a few changes to mpl svn HEAD
to support this, and added a new example.

  examples/event_handling/legend_picking.py

which I'll include below. JJ could you review the changes to legend.py?

Instructions for checking out svn are at::

http://matplotlib.sourceforge.net/faq/installing_faq.html#install-from-svn

Here is the example:

"""
Enable picking on the legend to toggle the legended line on and off
"""
import numpy as np
import matplotlib.pyplot as plt

t = np.arange(0.0, 0.2, 0.1)
y1 = 2*np.sin(2*np.pi*t)
y2 = 4*np.sin(2*np.pi*2*t)

fig = plt.figure()
ax = fig.add_subplot(111)

line1, = ax.plot(t, y1, lw=2, color='red', label='1 hz')
line2, = ax.plot(t, y2, lw=2, color='blue', label='2 hz')

leg = ax.legend(loc='upper left', fancybox=True, shadow=True)
leg.get_frame().set_alpha(0.4)

lines = [line1, line2]
lined = dict()
for legline, realine in zip(leg.get_lines(), lines):
    legline.set_picker(5) # 5 pts tolerance
    lined[legline] = realine

def onpick(event):
    legline = event.artist
    realline = lined[legline]
    vis = realline.get_visible()
    realline.set_visible(not vis)
    fig.canvas.draw()

fig.canvas.mpl_connect('pick_event', onpick)

plt.show()

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008
30-Day
trial. Simplify your report design, integration and deployment - and focus
on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
View this message in context: http://www.nabble.com/Hiding-data-via-legend-tp24802219p25531267.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Hi,

pickers work great to make matplotlib plots more interactive/general user
friendly.

On the subject of the legend_picker.py example, I was wondering if it was
possible to combine both a legend picker and a line picker in the same plot.
From what I gather they will both use the same onpick event callback.

So my question is : How do I discriminate between a pick on the legend from
a pick on a line ? The event.artist is a line2D in both cases.

As demonstrated in the above example, leg.get_lines() gives you the
list of lines inside the legend. The list of original lines is kept in
ax.lines.
So, you can check in which list the given artist is.

Regards,

-JJ

···

On Wed, Sep 23, 2009 at 3:27 PM, butterw <butterw@...287...> wrote:

John Hunter-4 wrote:

On Mon, Aug 3, 2009 at 11:38 PM, Gökhan Sever<gokhansever@...287...> >> wrote:

Hello,

I was wondering if it is possible to hide some data on figures using a
say
right click option to any of the legend entry and make it temporarily
hidden/visible to better analyse the rest of the data?

Check this screenshot for example:

http://img25.imageshack.us/img25/9427/datahiding.png

The red data clutters the rest of the figure, and I would like to be able
to
hide it temporarily so that I can investigate the other two relations
more
easily.

Any ideas? or alternative solutions?

It's a nice idea, and should be doable with the pick interface we have
for all mpl artists. Unfortunately, there were a few problems in the
legend implementation which blocked the pick events from hitting the
proxy lines they contained. I just made a few changes to mpl svn HEAD
to support this, and added a new example.

examples/event_handling/legend_picking.py

which I'll include below. JJ could you review the changes to legend.py?

Instructions for checking out svn are at::

http://matplotlib.sourceforge.net/faq/installing_faq.html#install-from-svn

Here is the example:

"""
Enable picking on the legend to toggle the legended line on and off
"""
import numpy as np
import matplotlib.pyplot as plt

t = np.arange(0.0, 0.2, 0.1)
y1 = 2*np.sin(2*np.pi*t)
y2 = 4*np.sin(2*np.pi*2*t)

fig = plt.figure()
ax = fig.add_subplot(111)

line1, = ax.plot(t, y1, lw=2, color='red', label='1 hz')
line2, = ax.plot(t, y2, lw=2, color='blue', label='2 hz')

leg = ax.legend(loc='upper left', fancybox=True, shadow=True)
leg.get_frame().set_alpha(0.4)

lines = [line1, line2]
lined = dict()
for legline, realine in zip(leg.get_lines(), lines):
legline.set_picker(5) # 5 pts tolerance
lined[legline] = realine

def onpick(event):
legline = event.artist
realline = lined[legline]
vis = realline.get_visible()
realline.set_visible(not vis)
fig.canvas.draw()

fig.canvas.mpl_connect('pick_event', onpick)

plt.show()

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008
30-Day
trial. Simplify your report design, integration and deployment - and focus
on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
View this message in context: http://www.nabble.com/Hiding-data-via-legend-tp24802219p25531267.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Hi,

thank you for clearing that up.

Some feedback: If plotting a line2D as discrete points rather than a
continuous line, you must use numpoints=2 for the legend picking to actually
occur on the points. The alpha blending doesn't work on the legend symbols
however.

Is there any other way, I can show in the legend whether the points of the
series are visible or not ?

I thought of changing the labels, but failed to get them to redraw.

# plots:
ax.plot(t, y1, 'ro', picker=5, label='lab1')
ax.plot(t, y2, 'bo', picker=5, label='lab2')

# legend
leg = ax.legend(loc='upper left', numpoints=2, fancybox=True, shadow=True)
lines, labels = ax.get_legend_handles_labels()

# Enable picking on the legend lines
leglines=leg.get_lines()
for legline in leglines: legline.set_picker(5)

Jae-Joon Lee wrote:

···

On Wed, Sep 23, 2009 at 3:27 PM, butterw <butterw@...287...> wrote:

Hi,

pickers work great to make matplotlib plots more interactive/general user
friendly.

On the subject of the legend_picker.py example, I was wondering if it was
possible to combine both a legend picker and a line picker in the same
plot.
From what I gather they will both use the same onpick event callback.

So my question is : How do I discriminate between a pick on the legend
from
a pick on a line ? The event.artist is a line2D in both cases.

As demonstrated in the above example, leg.get_lines() gives you the
list of lines inside the legend. The list of original lines is kept in
ax.lines.
So, you can check in which list the given artist is.

Regards,

-JJ

John Hunter-4 wrote:

On Mon, Aug 3, 2009 at 11:38 PM, Gökhan Sever<gokhansever@...1896....> >>> wrote:

Hello,

I was wondering if it is possible to hide some data on figures using a
say
right click option to any of the legend entry and make it temporarily
hidden/visible to better analyse the rest of the data?

Check this screenshot for example:

http://img25.imageshack.us/img25/9427/datahiding.png

The red data clutters the rest of the figure, and I would like to be
able
to
hide it temporarily so that I can investigate the other two relations
more
easily.

Any ideas? or alternative solutions?

It's a nice idea, and should be doable with the pick interface we have
for all mpl artists. Unfortunately, there were a few problems in the
legend implementation which blocked the pick events from hitting the
proxy lines they contained. I just made a few changes to mpl svn HEAD
to support this, and added a new example.

  examples/event_handling/legend_picking.py

which I'll include below. JJ could you review the changes to
legend.py?

Instructions for checking out svn are at::

http://matplotlib.sourceforge.net/faq/installing_faq.html#install-from-svn

Here is the example:

"""
Enable picking on the legend to toggle the legended line on and off
"""
import numpy as np
import matplotlib.pyplot as plt

t = np.arange(0.0, 0.2, 0.1)
y1 = 2*np.sin(2*np.pi*t)
y2 = 4*np.sin(2*np.pi*2*t)

fig = plt.figure()
ax = fig.add_subplot(111)

line1, = ax.plot(t, y1, lw=2, color='red', label='1 hz')
line2, = ax.plot(t, y2, lw=2, color='blue', label='2 hz')

leg = ax.legend(loc='upper left', fancybox=True, shadow=True)
leg.get_frame().set_alpha(0.4)

lines = [line1, line2]
lined = dict()
for legline, realine in zip(leg.get_lines(), lines):
    legline.set_picker(5) # 5 pts tolerance
    lined[legline] = realine

def onpick(event):
    legline = event.artist
    realline = lined[legline]
    vis = realline.get_visible()
    realline.set_visible(not vis)
    fig.canvas.draw()

fig.canvas.mpl_connect('pick_event', onpick)

plt.show()

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008
30-Day
trial. Simplify your report design, integration and deployment - and
focus
on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
View this message in context:
http://www.nabble.com/Hiding-data-via-legend-tp24802219p25531267.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9&#45;12, 2009. Register
now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9&#45;12, 2009. Register
now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
View this message in context: http://www.nabble.com/Hiding-data-via-legend-tp24802219p25633860.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Hi,

thank you for clearing that up.

Some feedback: If plotting a line2D as discrete points rather than a
continuous line, you must use numpoints=2 for the legend picking to actually
occur on the points. The alpha blending doesn't work on the legend symbols
however.

I tried numpoints=1,2,3 but all worked for me. Can someone else confirm this?

The alpha for legend symbols does not work since, inside legend, the
lines and symbols are drawn by different artists.

Try something like below.

        legline.set_alpha(1.0)
        try:
            legline._legmarker.set_alpha(1.0)
        except AttributeError:
            pass

Is there any other way, I can show in the legend whether the points of the
series are visible or not ?

I thought of changing the labels, but failed to get them to redraw.

Legend.get_texts() method returns the list of Text instances.

http://matplotlib.sourceforge.net/api/artist_api.html?highlight=legend#matplotlib.legend.Legend.get_texts

You may modify the returned Text instances.

-JJ

···

On Sun, Sep 27, 2009 at 10:02 AM, butterw <butterw@...287...> wrote:

# plots:
ax.plot(t, y1, 'ro', picker=5, label='lab1')
ax.plot(t, y2, 'bo', picker=5, label='lab2')

# legend
leg = ax.legend(loc='upper left', numpoints=2, fancybox=True, shadow=True)
lines, labels = ax.get_legend_handles_labels()

# Enable picking on the legend lines
leglines=leg.get_lines()
for legline in leglines: legline.set_picker(5)

Jae-Joon Lee wrote:

On Wed, Sep 23, 2009 at 3:27 PM, butterw <butterw@...287...> wrote:

Hi,

pickers work great to make matplotlib plots more interactive/general user
friendly.

On the subject of the legend_picker.py example, I was wondering if it was
possible to combine both a legend picker and a line picker in the same
plot.
From what I gather they will both use the same onpick event callback.

So my question is : How do I discriminate between a pick on the legend
from
a pick on a line ? The event.artist is a line2D in both cases.

As demonstrated in the above example, leg.get_lines() gives you the
list of lines inside the legend. The list of original lines is kept in
ax.lines.
So, you can check in which list the given artist is.

Regards,

-JJ

John Hunter-4 wrote:

On Mon, Aug 3, 2009 at 11:38 PM, Gökhan Sever<gokhansever@...985.....> >>>> wrote:

Hello,

I was wondering if it is possible to hide some data on figures using a
say
right click option to any of the legend entry and make it temporarily
hidden/visible to better analyse the rest of the data?

Check this screenshot for example:

http://img25.imageshack.us/img25/9427/datahiding.png

The red data clutters the rest of the figure, and I would like to be
able
to
hide it temporarily so that I can investigate the other two relations
more
easily.

Any ideas? or alternative solutions?

It's a nice idea, and should be doable with the pick interface we have
for all mpl artists. Unfortunately, there were a few problems in the
legend implementation which blocked the pick events from hitting the
proxy lines they contained. I just made a few changes to mpl svn HEAD
to support this, and added a new example.

examples/event_handling/legend_picking.py

which I'll include below. JJ could you review the changes to
legend.py?

Instructions for checking out svn are at::

http://matplotlib.sourceforge.net/faq/installing_faq.html#install-from-svn

Here is the example:

"""
Enable picking on the legend to toggle the legended line on and off
"""
import numpy as np
import matplotlib.pyplot as plt

t = np.arange(0.0, 0.2, 0.1)
y1 = 2*np.sin(2*np.pi*t)
y2 = 4*np.sin(2*np.pi*2*t)

fig = plt.figure()
ax = fig.add_subplot(111)

line1, = ax.plot(t, y1, lw=2, color='red', label='1 hz')
line2, = ax.plot(t, y2, lw=2, color='blue', label='2 hz')

leg = ax.legend(loc='upper left', fancybox=True, shadow=True)
leg.get_frame().set_alpha(0.4)

lines = [line1, line2]
lined = dict()
for legline, realine in zip(leg.get_lines(), lines):
legline.set_picker(5) # 5 pts tolerance
lined[legline] = realine

def onpick(event):
legline = event.artist
realline = lined[legline]
vis = realline.get_visible()
realline.set_visible(not vis)
fig.canvas.draw()

fig.canvas.mpl_connect('pick_event', onpick)

plt.show()

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008
30-Day
trial. Simplify your report design, integration and deployment - and
focus
on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
View this message in context:
http://www.nabble.com/Hiding-data-via-legend-tp24802219p25531267.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9&#45;12, 2009. Register
now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9&#45;12, 2009. Register
now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
View this message in context: http://www.nabble.com/Hiding-data-via-legend-tp24802219p25633860.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Some feedback: If plotting a line2D as discrete points rather than a
continuous line, you must use numpoints=2 for the legend picking to actually
occur on the points. The alpha blending doesn't work on the legend symbols
however.

I tried numpoints=1,2,3 but all worked for me. Can someone else confirm this?

I'm using windows and mpl 0.99.0:
numpoints=2 or 3 work
with numpoints=1 the pick does not occur on the symbol but where it
would be with numpoints=2

The alpha for legend symbols does not work since, inside legend, the
lines and symbols are drawn by different artists.

Try something like below.

       legline.set_alpha(1.0)
       try:
           legline._legmarker.set_alpha(1.0)
       except AttributeError:
           pass

Is there any other way, I can show in the legend whether the points of the
series are visible or not ?

I thought of changing the labels, but failed to get them to redraw.

Legend.get_texts() method returns the list of Text instances.

http://matplotlib.sourceforge.net/api/artist_api.html?highlight=legend#matplotlib.legend.Legend.get_texts

You may modify the returned Text instances.

-JJ

works great.

···

On Sun, Sep 27, 2009 at 9:31 PM, Jae-Joon Lee <lee.j.joon@...287...> wrote:

# plots:
ax.plot(t, y1, 'ro', picker=5, label='lab1')
ax.plot(t, y2, 'bo', picker=5, label='lab2')

# legend
leg = ax.legend(loc='upper left', numpoints=2, fancybox=True, shadow=True)
lines, labels = ax.get_legend_handles_labels()

# Enable picking on the legend lines
leglines=leg.get_lines()
for legline in leglines: legline.set_picker(5)

Some feedback: If plotting a line2D as discrete points rather than a
continuous line, you must use numpoints=2 for the legend picking to actually
occur on the points. The alpha blending doesn't work on the legend symbols
however.

I tried numpoints=1,2,3 but all worked for me. Can someone else confirm this?

I'm using windows and mpl 0.99.0:

Most of the enhancements to support legend picking happened after 99.0
-- you probably need to be on svn trunk (I don't think 99.1 would work
either). The example is working fine for me on svn HEAD (regardless
of ncol) with one exception: if I use a marker instead of a line, the
alpha is not respected (the line markers are simply turned off).
Apparently we need to fix Line2D to respect the alpha setting for
markers in this use case.

JDH

···

On Sun, Sep 27, 2009 at 3:45 PM, Peter Butterworth <butterw@...287...> wrote:

On Sun, Sep 27, 2009 at 9:31 PM, Jae-Joon Lee <lee.j.joon@...287...> wrote:

The alpha for legend symbols does not work since, inside legend, the
lines and symbols are drawn by different artists.

Try something like below.

   legline\.set\_alpha\(1\.0\)
   try:
       legline\.\_legmarker\.set\_alpha\(1\.0\)
   except AttributeError:
       pass

Is there any other way, I can show in the legend whether the points of the
series are visible or not ?

I thought of changing the labels, but failed to get them to redraw.

Legend.get_texts() method returns the list of Text instances.

http://matplotlib.sourceforge.net/api/artist_api.html?highlight=legend#matplotlib.legend.Legend.get_texts

You may modify the returned Text instances.

-JJ

works great.

# plots:
ax.plot(t, y1, 'ro', picker=5, label='lab1')
ax.plot(t, y2, 'bo', picker=5, label='lab2')

# legend
leg = ax.legend(loc='upper left', numpoints=2, fancybox=True, shadow=True)
lines, labels = ax.get_legend_handles_labels()

# Enable picking on the legend lines
leglines=leg.get_lines()
for legline in leglines: legline.set_picker(5)

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Hi,

I am a bit surprised that a line that isn't visible remains pickable
by default :

        # toggle line visibility:
        vis = not line.get_visible()
        line.set_visible(vis)
        # by default a line would remain pickable even if not visible :
        if vis : line.set_picker(5)
        else : line.set_picker(None)

I've attached my line + legend picker example, in case it is of any
use to anybody.

legend_picking2.py (2.43 KB)

···

On Mon, Sep 28, 2009 at 3:43 AM, John Hunter <jdh2358@...287...> wrote:

On Sun, Sep 27, 2009 at 3:45 PM, Peter Butterworth <butterw@...287...> wrote:

On Sun, Sep 27, 2009 at 9:31 PM, Jae-Joon Lee <lee.j.joon@...287...> wrote:

Some feedback: If plotting a line2D as discrete points rather than a
continuous line, you must use numpoints=2 for the legend picking to actually
occur on the points. The alpha blending doesn't work on the legend symbols
however.

I tried numpoints=1,2,3 but all worked for me. Can someone else confirm this?

I'm using windows and mpl 0.99.0:

Most of the enhancements to support legend picking happened after 99.0
-- you probably need to be on svn trunk (I don't think 99.1 would work
either). The example is working fine for me on svn HEAD (regardless
of ncol) with one exception: if I use a marker instead of a line, the
alpha is not respected (the line markers are simply turned off).
Apparently we need to fix Line2D to respect the alpha setting for
markers in this use case.

JDH

The alpha for legend symbols does not work since, inside legend, the
lines and symbols are drawn by different artists.

Try something like below.

       legline.set_alpha(1.0)
       try:
           legline._legmarker.set_alpha(1.0)
       except AttributeError:
           pass

Is there any other way, I can show in the legend whether the points of the
series are visible or not ?

I thought of changing the labels, but failed to get them to redraw.

Legend.get_texts() method returns the list of Text instances.

http://matplotlib.sourceforge.net/api/artist_api.html?highlight=legend#matplotlib.legend.Legend.get_texts

You may modify the returned Text instances.

-JJ

works great.

# plots:
ax.plot(t, y1, 'ro', picker=5, label='lab1')
ax.plot(t, y2, 'bo', picker=5, label='lab2')

# legend
leg = ax.legend(loc='upper left', numpoints=2, fancybox=True, shadow=True)
lines, labels = ax.get_legend_handles_labels()

# Enable picking on the legend lines
leglines=leg.get_lines()
for legline in leglines: legline.set_picker(5)

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
thanks,
peter butterworth

Hello,

Are there any opinions how to make this legend picking work after a zoom or pan event? There is no way to bring the cursor into its beginning shape and therefore non of the clicking works as expected.

···

On Sun, Oct 4, 2009 at 9:37 AM, Peter Butterworth <butterw@…1972…> wrote:

Hi,

I am a bit surprised that a line that isn’t visible remains pickable

by default :

    # toggle line visibility:

    vis = not line.get_visible()

    line.set_visible(vis)

    # by default a line would remain pickable even if not visible :

    if vis : line.set_picker(5)

    else : line.set_picker(None)

I’ve attached my line + legend picker example, in case it is of any

use to anybody.

On Mon, Sep 28, 2009 at 3:43 AM, John Hunter <jdh2358@…287…> wrote:

On Sun, Sep 27, 2009 at 3:45 PM, Peter Butterworth <butterw@…287…> wrote:

On Sun, Sep 27, 2009 at 9:31 PM, Jae-Joon Lee <lee.j.joon@…287…> wrote:

Some feedback: If plotting a line2D as discrete points rather than a

continuous line, you must use numpoints=2 for the legend picking to actually

occur on the points. The alpha blending doesn’t work on the legend symbols

however.

I tried numpoints=1,2,3 but all worked for me. Can someone else confirm this?

I’m using windows and mpl 0.99.0:

Most of the enhancements to support legend picking happened after 99.0

– you probably need to be on svn trunk (I don’t think 99.1 would work

either). The example is working fine for me on svn HEAD (regardless

of ncol) with one exception: if I use a marker instead of a line, the

alpha is not respected (the line markers are simply turned off).

Apparently we need to fix Line2D to respect the alpha setting for

markers in this use case.

JDH

The alpha for legend symbols does not work since, inside legend, the

lines and symbols are drawn by different artists.

Try something like below.

   legline.set_alpha(1.0)
   try:
       legline._legmarker.set_alpha(1.0)
   except AttributeError:
       pass

Is there any other way, I can show in the legend whether the points of the

series are visible or not ?

I thought of changing the labels, but failed to get them to redraw.

Legend.get_texts() method returns the list of Text instances.

http://matplotlib.sourceforge.net/api/artist_api.html?highlight=legend#matplotlib.legend.Legend.get_texts

You may modify the returned Text instances.

-JJ

works great.

plots:

ax.plot(t, y1, ‘ro’, picker=5, label=‘lab1’)

ax.plot(t, y2, ‘bo’, picker=5, label=‘lab2’)

legend

leg = ax.legend(loc=‘upper left’, numpoints=2, fancybox=True, shadow=True)

lines, labels = ax.get_legend_handles_labels()

Enable picking on the legend lines

leglines=leg.get_lines()

for legline in leglines: legline.set_picker(5)


Come build with us! The BlackBerry® Developer Conference in SF, CA

is the only developer event you need to attend this year. Jumpstart your

developing skills, take BlackBerry mobile applications to market and stay

ahead of the curve. Join us from November 9-12, 2009. Register now!

http://p.sf.net/sfu/devconf


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

thanks,

peter butterworth


Come build with us! The BlackBerry® Developer Conference in SF, CA

is the only developer event you need to attend this year. Jumpstart your

developing skills, take BlackBerry mobile applications to market and stay

ahead of the curve. Join us from November 9-12, 2009. Register now!

http://p.sf.net/sfu/devconf


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Gökhan