[Chaco] Having a legend outsite plot area

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

[Chaco] Having a legend outsite plot area

Fabio Pliger
Hi Guys,

Is it possible to make chack draw a plot Legend outside the plotting area? For instance I have a VPlotContainer  on wich i've add all my line_plots and a LegendTool to show legends... but legend tool is always disturbing, hidding the some plot lines segments.. Event it's possible to move the legend around the plot are the problem still if I need to print the plot or export it to an image file. So... I'd like to have the Legend to be placed stacked after the plot are ( under the x-axis of the plot ). Is it possible? Any idea?

Thanks

Fabio

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

Re: [Chaco] Having a legend outsite plot area

bryce hendrix-2
On Sun, Oct 17, 2010 at 3:50 AM, Fabio Pliger <[hidden email]> wrote:
Hi Guys,

Is it possible to make chack draw a plot Legend outside the plotting area? For instance I have a VPlotContainer  on wich i've add all my line_plots and a LegendTool to show legends... but legend tool is always disturbing, hidding the some plot lines segments.. Event it's possible to move the legend around the plot are the problem still if I need to print the plot or export it to an image file. So... I'd like to have the Legend to be placed stacked after the plot are ( under the x-axis of the plot ). Is it possible? Any idea?


Fabio,

Sorry the the wait. You have 4 options if you want to remove the legend:

 * expose the ability to show/hide the legend (key press, button, etc)
 * make the plot padding really big on one side and move the legend onto the padding
 * create a view for the legend and display it outside of the plot
 * inherit from the legend, but draw it differently

#1, #2 and #4 are pretty straightforward. If you go the route of #1, I suggest using ToolbarPlot instead of Plot and adding a button to it for showing/hiding the legend. The ToolbarPlot is nice if you want to use its ability to copy to the clipboard or export it because it will remove the toolbar from the exported plot.

We used to have some code which did #3, but I can't seem to find it. I'd suggest something like this (I used the default editor for the labels, you'll probably want something fancier):

class LegendView(HasTraits):
    legend = Instance(Legend)
    labels = Property(List, depends_on='legend._cached_label_names')

    traits_view = View(Item('labels'))

    @cached_property
    def get_labels(self):
        return self.legend._cached_label_names

Bryce



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

[Chaco] Having a legend outsite plot area

Fabio Pliger
In reply to this post by Fabio Pliger
Bryce wrote: 
[snip]...
Fabio, Sorry the the wait.
No wait.. thank you for answering!
 
You have 4 options if you want to remove the legend:

 * expose the ability to show/hide the legend (key press, button, etc)
 * make the plot padding really big on one side and move the legend onto the
padding
 * create a view for the legend and display it outside of the plot
 * inherit from the legend, but draw it differently

#1, #2 and #4 are pretty straightforward. If you go the route of #1, I
suggest using ToolbarPlot instead of Plot and adding a button to it for
showing/hiding the legend. The ToolbarPlot is nice if you want to use its
ability to copy to the clipboard or export it because it will remove the
toolbar from the exported plot.

We used to have some code which did #3, but I can't seem to find it. I'd
suggest something like this (I used the default editor for the labels,
you'll probably want something fancier):

class LegendView(HasTraits):
    legend = Instance(Legend)
    labels = Property(List, depends_on='legend._cached_label_names')

    traits_view = View(Item('labels'))

    @cached_property
    def get_labels(self):
        return self.legend._cached_label_names

Bryce
Ok. My choice went to option number 3! Great!  :)

Now i've managed to display a nice list under my plot. Great! The next step i'd like to do is to render the labels the same way the legends do on the plot area ( with the line marker in front and the label )... also because i'm using a sort of Highlight Legend picked from the examples online.. So i'd really like to obtain this layout effect. I've tryied to go deeper inside chaco elements but had no luck... The big picture i've got is that the plot components and all its elements and tools are drawn inside a ComponentEditor.. but didn't make to figure out how to place my HighlightLegend to be rendered inside the LegendView.

In case you say that's kinda not possible i'll try other ways of placing line colors and stuff inside a TableEditor...  :)

thanks very much for your help!

cheers

Fabio

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