lasso selection speed

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

lasso selection speed

Christian K.
Hi,

I noticed that the lasso selection tool used on a scatter plot becomes quite
slow when there are many plots even though they are in other containers. For  
example: I have a scatter plot with about 100 pts and besides another plot
with some ten line plots each having only 6 pts. Then the lasso selection in
the scatter plot is only slowly updating the blue selection area whereas when
the lineplot shows only some lines, lasso selection is pretty responsive.
Is there anything I can do about that?

Cheers, Christian


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

Re: lasso selection speed

Peter Wang
On Mon, Nov 8, 2010 at 9:23 AM, Christian K. <[hidden email]> wrote:
> I noticed that the lasso selection tool used on a scatter plot becomes quite
> slow when there are many plots even though they are in other containers. For
> example: I have a scatter plot with about 100 pts and besides another plot
> with some ten line plots each having only 6 pts. Then the lasso selection in
> the scatter plot is only slowly updating the blue selection area whereas when
> the lineplot shows only some lines, lasso selection is pretty responsive.
> Is there anything I can do about that?
>
> Cheers, Christian

This certainly shouldn't be the case... Is there any way you can send
a code sample that demonstrates this problem?

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

Re: lasso selection speed

Christian K.
Peter Wang <pwang@...> writes:

>
> On Mon, Nov 8, 2010 at 9:23 AM, Christian K. <ckkart@...> wrote:
> > I noticed that the lasso selection tool used on a scatter plot becomes
quite
> > slow when there are many plots even though they are in other containers.
For
> > example: I have a scatter plot with about 100 pts and besides another plot
> > with some ten line plots each having only 6 pts. Then the lasso selection
in
> > the scatter plot is only slowly updating the blue selection area whereas
when
> > the lineplot shows only some lines, lasso selection is pretty responsive.
> > Is there anything I can do about that?
> >
> > Cheers, Christian
>
> This certainly shouldn't be the case... Is there any way you can send
> a code sample that demonstrates this problem?

Yes, sure. In the example, based on the selection in the scatter plot, line
plots are added to the plot on the left. The speed of the selection tool then
depends on the previous selection, i.e. the more line plots shown on the left,
the slower the lasso tool.

Christian

-snip------

import numpy as N
from numpy import arange, sort, compress, arange
from numpy.random import random

# Enthought library imports
from enthought.chaco.api import ArrayPlotData, HPlotContainer, \
                                 Plot, LassoOverlay
                                 

from enthought.enable.component_editor import ComponentEditor
from enthought.chaco.tools.api import LassoSelection, ScatterInspector
     
#from enthought.enable.api import Window
from enthought.traits.api import HasTraits
from enthought.traits.ui.api import Item, View, NoButtons
from enthought.chaco.example_support import COLOR_PALETTE
     
     
class View(HasTraits):
   
    traits_view = View(
        Item('container',
             editor=ComponentEditor(),
             show_label=False, resizable=True ),
        buttons=NoButtons,
 
        width=1000, height=500,
        title='demo',
        resizable=True)

    def __init__(self, *args, **kwargs):
        super(View, self).__init__(*args, **kwargs)

        self.create_plot()
       
    def create_plot(self):
        # plot ang                  

        self.pd_lines = ArrayPlotData()
        self.plot_lines = Plot(self.pd_lines, resizable="hv", padding=30)

        # plot conf
       
        # Create some data
        npts = 2000
        x = sort(random(npts))
        y = random(npts)

        self.pd_scatter = ArrayPlotData()        
        self.pd_scatter.set_data('x', x)
        self.pd_scatter.set_data('y', y)
       
        self.plot_scatter = Plot(self.pd_scatter, resizable="hv", padding=30)
        self.plot_scatter.plot(('x','y'), type='scatter', marker='circle',
                                name='dot', index_sort='ascending')

        plt = self.plot_scatter.plots['dot'][0]
       
        lasso_selection = LassoSelection(component=plt,
                                         selection_datasource=plt.index)
        plt.active_tool = lasso_selection
       
        plt.tools.append(ScatterInspector(plt))
        lasso_overlay = LassoOverlay(lasso_selection=lasso_selection,
                                     component=plt)
        plt.overlays.append(lasso_overlay)        
       
        self.index_datasource = plt.index
        lasso_selection.on_trait_change(self._selection_changed,
                                        'selection_changed')        
       
        # Create a container and add components
        self.container = HPlotContainer(padding=0, fill_padding=True,
                                        bgcolor = "white",
                                        use_backbuffer=False)
   
        self.container.add(self.plot_lines)
        self.container.add(self.plot_scatter)
       
    def clear(self):
        for k in self.plot_lines.plots.keys():
            self.plot_lines.delplot(k)        
       
        self.container.invalidate_draw()
        self.container.request_redraw()    
                     
    def update_plot(self):  
        self.clear()
       
        x = N.linspace(0,10,10)
        for n,k in enumerate(self.selection):
            y = N.sin(x*k+k)
            self.pd_lines.set_data('x%d'%n, x)
            self.pd_lines.set_data('y%d'%n, y)
            self.plot_lines.plot(('x%d'%n,'y%d'%n), type='line',
                                  color=COLOR_PALETTE[n%10])
                           
        self.container.invalidate_draw()
        self.container.request_redraw()        

    def _selection_changed(self, *args):
        mask = self.index_datasource.metadata['selection']
        mask = N.compress(mask, N.arange(len(mask)))
        self.selection  = mask
        self.update_plot()

def main():
    a = View()
    a.configure_traits()    
   
if __name__ == '__main__':
    main()


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

Re: lasso selection speed

Peter Wang
On Mon, Nov 8, 2010 at 2:54 PM, Christian K. <[hidden email]> wrote:
> Yes, sure. In the example, based on the selection in the scatter plot, line
> plots are added to the plot on the left. The speed of the selection tool then
> depends on the previous selection, i.e. the more line plots shown on the left,
> the slower the lasso tool.

Thanks for sending along the code sample.  When only ten line plots
are drawn, the lasso still seems pretty speedy.  However, it's very
easy to select hundreds of points, and then you have hundreds of line
plots on the left, which can certainly get a little unwieldy.

The solution is to enable backbuffering on the line plot.  Near the
top of create_plot(), when self.plot_lines is first initialized, set
the following:

       self.plot_lines.use_backbuffer = True
       self.plot_lines.unified_draw = True

This will make the lasso update quickly even when hundreds of lines
are drawn in the line plot.


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

Re: lasso selection speed

Christian K.
In reply to this post by Christian K.
Peter Wang <pwang@...> writes:

> The solution is to enable backbuffering on the line plot.  Near the
> top of create_plot(), when self.plot_lines is first initialized, set
> the following:
>
>        self.plot_lines.use_backbuffer = True
>        self.plot_lines.unified_draw = True
>
> This will make the lasso update quickly even when hundreds of lines
> are drawn in the line plot.

Thanks a lot.
Without backbuffering: is chaco constantly redrawing all plots while making a
lasso selection?

Christian

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

Re: lasso selection speed

Peter Wang
On Tue, Nov 9, 2010 at 12:08 AM, Christian K. <[hidden email]> wrote:
> Thanks a lot.
> Without backbuffering: is chaco constantly redrawing all plots while making a
> lasso selection?

Yes.  This gives us the ability to do very interesting and dynamic
visualizations that have shared selection and brushing across plots,
but it can get computationally intensive if there are a lot of points
or plots.  Thus, the backbuffering feature was built in at the outset.

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