figlegend

Sæl !

I have installed matplotlib-0.52 and succesfully ran the figlegend example.
However when I try to run it directly in my program into a figure i am not as successful:
- I can create the legend with
leg=matplotlib.matlab.figlegend(tuple([i[1] for i in d]),tuple([i[0] for i in d]),'upper center')
leg.draw()
But it does not appear anywhere

If I try to call figlegend from the canvas, canvas.Figure or canvas.Figure.axes[0], I get an erro message as figlegend is not defined in any of these contexts
  canvas.figure.figlegend(tuple([i[1] for i in d]),tuple([i[0] for i in d]),'upper center')
  AttributeError: Figure instance has no attribute 'figlegend'

How can I get my figlegend to appear in my window ?

Takk

Jean-Baptiste

···

On Fri, 12 Mar 2004 20:17:25 -0800 matplotlib-users-request@lists.sourceforge.net wrote:

Send Matplotlib-users mailing list submissions to
  matplotlib-users@lists.sourceforge.net

To subscribe or unsubscribe via the World Wide Web, visit
  matplotlib-users List Signup and Options
or, via email, send a message with subject or body 'help' to
  matplotlib-users-request@lists.sourceforge.net

You can reach the person managing the list at
  matplotlib-users-admin@lists.sourceforge.net

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Matplotlib-users digest..."

Today's Topics:

   1. invisilbe line (Jean-Baptiste Cazier)
   2. Re: invisilbe line (John Hunter)

--__--__--

Message: 1
Date: Fri, 12 Mar 2004 12:40:19 +0000
From: Jean-Baptiste Cazier <Jean-Baptiste.cazier@...15...>
To: matplotlib-users@lists.sourceforge.net
Organization: deCODE Genetics
Subject: [Matplotlib-users] invisilbe line

S=E6l !

Is there a way to "turn-off" lines without removing the data ?
My goal is to hide some lines in a plot wihtout losing the data so I can sh=
ow it again later.
I can do=20
# Hide the line
x=3Dline.get_xdata()
y=3Dline.get_ydata()
line.set_data(,)

# Reset the line
line.set_data(x,y)

But I would prefer I more elegant way like
line.hide()
line.show()

Would it be possible to get something like that ?

Thanks

Jean-Baptiste

--=20
-----------------------------
Jean-Baptiste.Cazier@...15...

Department of Statistics
deCODE genetics Sturlugata,8
570 2993 101 Reykjav=EDk

--__--__--

Message: 2
To: Jean-Baptiste Cazier <Jean-Baptiste.cazier@...15...>
Cc: matplotlib-users@lists.sourceforge.net
Subject: Re: [Matplotlib-users] invisilbe line
From: John Hunter <jdhunter@...4...>
Date: Fri, 12 Mar 2004 12:29:18 -0600

--=-=-=
Content-Transfer-Encoding: quoted-printable

>>>>> "Jean-Baptiste" =3D=3D Jean-Baptiste Cazier <Jean-Baptiste.cazier@...124...=
ecode.is> writes:

    Jean-Baptiste> S=E6l ! Is there a way to "turn-off" lines without
    Jean-Baptiste> removing the data ? My goal is to hide some lines
    Jean-Baptiste> in a plot wihtout losing the data so I can show it
    Jean-Baptiste> again later. I can do # Hide the line
    Jean-Baptiste> x=3Dline.get_xdata() y=3Dline.get_ydata()
    Jean-Baptiste> line.set_data(,)

This can be done very easily (for any artist) with a minor
modification of artist.py. The base class forewards all drawing to
the derived classes so no other changes are required. Just replace
artist.py with the attached file below and then you can do:

    from matplotlib.matlab import *

    x =3D arange(0.0, 1.0, 0.05)
    l1, l2 =3D plot(x, sin(2*pi*x), x, sin(4*pi*x))
    l1.set_visible(False)
    show()

--=-=-=
Content-Type: application/octet-stream
Content-Disposition: attachment; filename=artist.py

from __future__ import division
import sys

from cbook import True, False, enumerate
from transforms import RWRef

class DPI(RWRef):
    'DPI as a read/write reference'
    pass
    
class Artist:
    """
    Abstract base class for someone who renders into a Figure

    Public attributes
      dpi : a DPI instance
      bbox : a Bound2D instance in display coords
      transform : a Transform instance
      renderer : the last renderer used to draw, or None
    """

    aname = 'Artist'
    def __init__(self, dpi, bbox):
        self.renderer = None
        self._lod = False
        self.dpi = dpi
        self.bbox = bbox
        self._clipOn = True
        self._alpha = 1.0
        self._visible = True
        
    def get_alpha(self):
        """
        Return the alpha value used for blending - not supported on
        all backends
        """
        return self._alpha

    def get_visible(self, b):
        "return the artist's visiblity"
        return self._visible

    def get_clip_on(self):
        'Return whether artist uses clipping'
        return self._clipOn

    def set_clip_on(self, b):
        'Set whether artist is clipped to bbox'
        self._clipOn = b

    def set_visible(self, b):
        "set the artist's visiblity"
        self._visible = b
    
    def set_child_attr(self, attr, val):
        """
        Set attribute attr for self, and all child artists
        """
        setattr(self, attr, val)
        for c in self.get_child_artists():
            c.set_child_attr(attr, val)

    def get_child_artists(self):
        'Return all artists contained in self'
        return

    def get_window_extent(self, renderer=None):
        'Return the window extent of the Artist as a Bound2D instance'
        raise NotImplementedError('Derived must override')

    def get_dpi(self):
        """
        Get the DPI of the display
        """
        return self._dpi

    def draw(self, renderer=None, *args, **kwargs):
        'Derived classes drawing method'
        if not self._visible: return
        if renderer is None: renderer = self.renderer
        if renderer is None: return
        self.renderer = renderer
        
        self._draw(renderer, *args, **kwargs)

    def _draw(self, renderer, *args, **kwargs):
        'Derived classes drawing method'
        raise NotImplementedError, 'Derived must override'

    def set_alpha(self, alpha):
        """
        Set the alpha value used for blending - not supported on
        all backends
        """
        self._alpha = alpha

    def set_lod(self, on):
        """
        Set Level of Detail on or off. If on, the artists may examine
        things like the pixel width of the axes and draw a subset of
        their contents accordingly
        """
        self._lod = on

--=-=-=

You'll still have a little function call overhead, but it should be
*significantly faster* than your current approach.

JDH

--=-=-=--

--__--__--

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

End of Matplotlib-users Digest

--
-----------------------------
Jean-Baptiste.Cazier@...15...

Department of Statistics
deCODE genetics Sturlugata,8
570 2993 101 Reykjavík