Addig a Legend with Plot().plot()

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Addig a Legend with Plot().plot()

Jim Radke

Hi,

 

I see examples of adding a Legend when a line is plotted with create_line_plot() and then a dictionary is created associating each line with a  string.  But I

 

      for i in range(4):

       plot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[i]), width=2.0)

       plots["Bessel j_%d"%i] = plot

 

    legend = Legend(component=container, padding=10, align="ur")

    legend.tools.append(LegendTool(legend, drag_button="right"))

    container.overlays.append(legend)

    legend.plots = plots

 

 

But I am plotting the lines by referencing data in an ArrayPlotData object and my container is a Plot() object.

 

    for i,signal in enumerate(signals):

        self.plotcontainer.plot(("ts", signal.Name), name=signal.Name, type="line", color=Colors.get_color(i))

 

 

So I am not sure how to populate the dictionary  “plots["Bessel j_%d"%i] = plot” since I don’t create a line with create_line_plot().

 

What is the best add a legend ?  My code is shown below… any help greatly appreciated!

 

Thanks

Jim Radke

[hidden email]

 

 

 

class PlotTab(wx.Panel):

    def __init__(self, parent):

        wx.Panel.__init__(self, parent)

        self.DataTable = None

        self.linesPLotted = []

 

        # buidl array and plot objects

        self.arrayPlotData = ArrayPlotData()

        self.plotcontainer = Plot(self.arrayPlotData)

        self.linesPlotted = []

        self.plotcontainer.overlays.append(ZoomTool(self.plotcontainer, drag_button="left", always_on=True, tool_mode="range", axis="index"))

 

        self.plot = Window(self, component = self.plotcontainer)

 

        sizer = wx.BoxSizer(wx.VERTICAL)

        sizer.Add(self.plot.control, 1, wx.EXPAND)

        self.SetSizer(sizer)

 

    def update_plot(self, signals=None, datatable=None):

        """ Update plot based on selected signals """

        if signals is None or (datatable is None and self.DataTable is None):

            return

        if datatable is not None:

            self.DataTable = datatable

 

        # remove existing lines from plot and data from data array

        for line in self.linesPlotted:

            self.plotcontainer.delplot(line)

        for name in self.arrayPlotData.list_data():

            self.arrayPlotData.del_data(name)

        self.plotcontainer.datasources.clear()

 

        # Add data to attray

        for signal in signals:

            self.arrayPlotData.set_data(name=signal.Name,    new_data=self.DataTable.Data[signal.Name])

        self.arrayPlotData.set_data(name="ts", new_data=(self.DataTable.Data['ts']/1000)) # always need the timestamp

 

        # Add lines to plot

        print ''

        self.linesPlotted = list()

        for i,signal in enumerate(signals):

            self.plotcontainer.plot(("ts", signal.Name),  name=signal.Name, type="line", color=Colors.get_color(i))

           

            plot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[i]), width=2.0)

           

            self.linesPlotted.append(signal.Name)

            print 'Plotting %s' % signal.Name

 

        self.plotcontainer.overlays.append(ZoomTool(self.plotcontainer, drag_button="left", always_on=True, tool_mode="range", axis="index"))

        self.plotcontainer.x_axis = ScalesPlotAxis(self.plotcontainer, orientation='bottom', title='Time', tick_generator=ScalesTickGenerator(scale=CalendarScaleSystem()))



This e-mail and its attachments are intended only for the individual or entity to whom it is addressed and may contain information that is confidential, privileged, inside information, or subject to other restrictions on use or disclosure. Any unauthorized use, dissemination or copying of this transmission or the information in it is prohibited and may be unlawful. If you have received this transmission in error, please notify the sender immediately by return e-mail, and permanently delete or destroy this e-mail, any attachments, and all copies (digital or paper). Unless expressly stated in this e-mail, nothing in this message should be construed as a digital or electronic signature.

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Addig a Legend with Plot().plot()

Jim Radke

Hi,

 

I see examples of adding a Legend when a line is plotted with create_line_plot() and then a dictionary is created associating each line with a  string.  But I

 

      for i in range(4):

       plot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[i]), width=2.0)

       plots["Bessel j_%d"%i] = plot

 

    legend = Legend(component=container, padding=10, align="ur")

    legend.tools.append(LegendTool(legend, drag_button="right"))

    container.overlays.append(legend)

    legend.plots = plots

 

 

But I am plotting the lines by referencing data in an ArrayPlotData object and my container is a Plot() object.

 

    for i,signal in enumerate(signals):

        self.plotcontainer.plot(("ts", signal.Name), name=signal.Name, type="line", color=Colors.get_color(i))

 

 

So I am not sure how to populate the dictionary  “plots["Bessel j_%d"%i] = plot” since I don’t create a line with create_line_plot().

 

What is the best add a legend ?  My code is shown below… any help greatly appreciated!

 

Thanks

Jim Radke

[hidden email]

 

 

 

class PlotTab(wx.Panel):

    def __init__(self, parent):

        wx.Panel.__init__(self, parent)

        self.DataTable = None

        self.linesPLotted = []

 

        # buidl array and plot objects

        self.arrayPlotData = ArrayPlotData()

        self.plotcontainer = Plot(self.arrayPlotData)

        self.linesPlotted = []

        self.plotcontainer.overlays.append(ZoomTool(self.plotcontainer, drag_button="left", always_on=True, tool_mode="range", axis="index"))

 

        self.plot = Window(self, component = self.plotcontainer)

 

        sizer = wx.BoxSizer(wx.VERTICAL)

        sizer.Add(self.plot.control, 1, wx.EXPAND)

        self.SetSizer(sizer)

 

    def update_plot(self, signals=None, datatable=None):

        """ Update plot based on selected signals """

        if signals is None or (datatable is None and self.DataTable is None):

            return

        if datatable is not None:

            self.DataTable = datatable

 

        # remove existing lines from plot and data from data array

        for line in self.linesPlotted:

            self.plotcontainer.delplot(line)

        for name in self.arrayPlotData.list_data():

            self.arrayPlotData.del_data(name)

        self.plotcontainer.datasources.clear()

 

        # Add data to attray

        for signal in signals:

            self.arrayPlotData.set_data(name=signal.Name,    new_data=self.DataTable.Data[signal.Name])

        self.arrayPlotData.set_data(name="ts", new_data=(self.DataTable.Data['ts']/1000)) # always need the timestamp

 

        # Add lines to plot

        print ''

        self.linesPlotted = list()

        for i,signal in enumerate(signals):

            self.plotcontainer.plot(("ts", signal.Name),  name=signal.Name, type="line", color=Colors.get_color(i))

           

            plot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[i]), width=2.0)

           

            self.linesPlotted.append(signal.Name)

            print 'Plotting %s' % signal.Name

 

        self.plotcontainer.overlays.append(ZoomTool(self.plotcontainer, drag_button="left", always_on=True, tool_mode="range", axis="index"))

        self.plotcontainer.x_axis = ScalesPlotAxis(self.plotcontainer, orientation='bottom', title='Time', tick_generator=ScalesTickGenerator(scale=CalendarScaleSystem()))



This e-mail and its attachments are intended only for the individual or entity to whom it is addressed and may contain information that is confidential, privileged, inside information, or subject to other restrictions on use or disclosure. Any unauthorized use, dissemination or copying of this transmission or the information in it is prohibited and may be unlawful. If you have received this transmission in error, please notify the sender immediately by return e-mail, and permanently delete or destroy this e-mail, any attachments, and all copies (digital or paper). Unless expressly stated in this e-mail, nothing in this message should be construed as a digital or electronic signature.

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Addig a Legend with Plot().plot()

Peter Wang
On Mon, Oct 18, 2010 at 9:30 AM, Jim Radke <[hidden email]> wrote:
> Hi,
> But I am plotting the lines by referencing data in an ArrayPlotData object
> and my container is a Plot() object.
...
> So I am not sure how to populate the dictionary  “plots["Bessel j_%d"%i] =
> plot” since I don’t create a line with create_line_plot().
> What is the best add a legend ?  My code is shown below… any help greatly
> appreciated!

Plot objects already have a legend instance associated with them, and
all plots you create using any of its .plot/.img_plot/etc. methods
will be inserted into the legend.  However, the legend is not visible
by default, so you need to toggle its .visible attribute:

    plot.legend.visible = True

-Peter
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Addig a Legend with Plot().plot()

Jim Radke
Thank you, you guys are great responding to emails so quickly !

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Peter Wang
Sent: Monday, October 18, 2010 1:42 PM
To: [hidden email]
Subject: Re: [Enthought-Dev] Addig a Legend with Plot().plot()

On Mon, Oct 18, 2010 at 9:30 AM, Jim Radke <[hidden email]> wrote:
> Hi,
> But I am plotting the lines by referencing data in an ArrayPlotData object
> and my container is a Plot() object.
...
> So I am not sure how to populate the dictionary  “plots["Bessel j_%d"%i] =
> plot” since I don’t create a line with create_line_plot().
> What is the best add a legend ?  My code is shown below… any help greatly
> appreciated!

Plot objects already have a legend instance associated with them, and
all plots you create using any of its .plot/.img_plot/etc. methods
will be inserted into the legend.  However, the legend is not visible
by default, so you need to toggle its .visible attribute:

    plot.legend.visible = True

-Peter
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev

This e-mail and its attachments are intended only for the individual or entity to whom it is addressed and may contain information that is confidential, privileged, inside information, or subject to other restrictions on use or disclosure. Any unauthorized use, dissemination or copying of this transmission or the information in it is prohibited and may be unlawful. If you have received this transmission in error, please notify the sender immediately by return e-mail, and permanently delete or destroy this e-mail, any attachments, and all copies (digital or paper). Unless expressly stated in this e-mail, nothing in this message should be construed as a digital or electronic signature.
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev