many different colored rect

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

many different colored rect

Rob Forler
Hello,

Firstly I apologize if this was sent twice. My first attempt was rejected.

I'm having a difficult time understanding how color works with kiva.

I'm basically trying to fill a plot with many rectangles of differing size
and shape and color.

The first thing I looked at was CMapImagePlot. This creates what basically
looks like a uniform heatmap, but when you create an Image into kiva.agg
all you can do is pass in the colors you want, nothing about specific
location of the colors.

My next thought was to create a gc and for each rect I want to make set the
fill color like:

    def _render(self, gc, points):
        gc.save_state()
        gc.clip_to_rect(self.x, self.y, self.width, self.height)
        import numpy
        for x1,y1,y2,x2 in points:
            rect = (x1,y1,x2-x1,y2-y1)
            gc.set_stroke_color(self.edge_color_)
            gc.set_line_width(self.edge_width)
            gc.set_line_dash(self.edge_style_)
            gc.set_fill_color((numpy.random.rand(), numpy.random.rand(),
numpy.random.rand(), numpy.random.rand()))
            gc.rect(*rect)
            gc.close_path()
            gc.draw_path()

        gc.restore_state()

This works, but I don't believe this is going to be very efficient. I'm
thinking on the order of len(points) == 4000.

What is the best way to do achieve this?  The project I'm currently working
on is using Chaco-3.2.0-py2.5-linux-x86_64.egg

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

"updated" event on ui

Bruce Dayton
Hi everyone,

I have a class Foo which is part of a view.

When Foo changes, I have a handler which triggers a ui update:

/class FooHandler(Handler):
/     /def object_foo_changed(self, info):
/         /if info.initialized:
/             /info.ui.updated = True

///

The problem that I am encountering is that when the ui is rebuilt it is
relocated back to its original position. I.e , if the user relocates the
ui to a new position, then changes foo, the ui updates and sanps back to
the original location.

Questions: is there a better way of updating the ui when foo chances? Or
is there a way to stop the rebuilt ui from snapping back to its original
position?

Thanks in advance,

Bruce

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

Re: many different colored rect

John Wiggins
In reply to this post by Rob Forler
Your best bet might be to use the rects() method of the graphics
context on groups of rectangles.

rects = [(x0,y0,w0,h0), (x1,y1,w1,h1), ... (xn,yn,wn,hn)]
gc.rects(rects)

You would need group the rectangles by color of course. Something like:
for color, rects in rect_groups:
    with gc:
        gc.begin_path()
        gc.set_fill_color(color)
        gc.rects(rects)
        gc.draw_path()

- John

On Tue, Nov 15, 2011 at 11:59 AM, Rob Forler <[hidden email]> wrote:

> Hello,
>
> Firstly I apologize if this was sent twice. My first attempt was rejected.
>
> I'm having a difficult time understanding how color works with kiva.
>
> I'm basically trying to fill a plot with many rectangles of differing size
> and shape and color.
>
> The first thing I looked at was CMapImagePlot. This creates what basically
> looks like a uniform heatmap, but when you create an Image into kiva.agg
> all you can do is pass in the colors you want, nothing about specific
> location of the colors.
>
> My next thought was to create a gc and for each rect I want to make set the
> fill color like:
>
>    def _render(self, gc, points):
>        gc.save_state()
>        gc.clip_to_rect(self.x, self.y, self.width, self.height)
>        import numpy
>        for x1,y1,y2,x2 in points:
>            rect = (x1,y1,x2-x1,y2-y1)
>            gc.set_stroke_color(self.edge_color_)
>            gc.set_line_width(self.edge_width)
>            gc.set_line_dash(self.edge_style_)
>            gc.set_fill_color((numpy.random.rand(), numpy.random.rand(),
> numpy.random.rand(), numpy.random.rand()))
>            gc.rect(*rect)
>            gc.close_path()
>            gc.draw_path()
>
>        gc.restore_state()
>
> This works, but I don't believe this is going to be very efficient. I'm
> thinking on the order of len(points) == 4000.
>
> What is the best way to do achieve this?  The project I'm currently working
> on is using Chaco-3.2.0-py2.5-linux-x86_64.egg
>
> Thanks,
> Rob
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: many different colored rect

Rob Forler
That certainly makes sense. I'm not certain how much "grouping" on color
will exist. I'll give this a stab.

On Tue, Nov 15, 2011 at 9:32 PM, John Wiggins <[hidden email]>wrote:

> Your best bet might be to use the rects() method of the graphics
> context on groups of rectangles.
>
> rects = [(x0,y0,w0,h0), (x1,y1,w1,h1), ... (xn,yn,wn,hn)]
> gc.rects(rects)
>
> You would need group the rectangles by color of course. Something like:
> for color, rects in rect_groups:
>    with gc:
>        gc.begin_path()
>        gc.set_fill_color(color)
>        gc.rects(rects)
>        gc.draw_path()
>
> - John
>
> On Tue, Nov 15, 2011 at 11:59 AM, Rob Forler <[hidden email]> wrote:
> > Hello,
> >
> > Firstly I apologize if this was sent twice. My first attempt was
> rejected.
> >
> > I'm having a difficult time understanding how color works with kiva.
> >
> > I'm basically trying to fill a plot with many rectangles of differing
> size
> > and shape and color.
> >
> > The first thing I looked at was CMapImagePlot. This creates what
> basically
> > looks like a uniform heatmap, but when you create an Image into kiva.agg
> > all you can do is pass in the colors you want, nothing about specific
> > location of the colors.
> >
> > My next thought was to create a gc and for each rect I want to make set
> the
> > fill color like:
> >
> >    def _render(self, gc, points):
> >        gc.save_state()
> >        gc.clip_to_rect(self.x, self.y, self.width, self.height)
> >        import numpy
> >        for x1,y1,y2,x2 in points:
> >            rect = (x1,y1,x2-x1,y2-y1)
> >            gc.set_stroke_color(self.edge_color_)
> >            gc.set_line_width(self.edge_width)
> >            gc.set_line_dash(self.edge_style_)
> >            gc.set_fill_color((numpy.random.rand(), numpy.random.rand(),
> > numpy.random.rand(), numpy.random.rand()))
> >            gc.rect(*rect)
> >            gc.close_path()
> >            gc.draw_path()
> >
> >        gc.restore_state()
> >
> > This works, but I don't believe this is going to be very efficient. I'm
> > thinking on the order of len(points) == 4000.
> >
> > What is the best way to do achieve this?  The project I'm currently
> working
> > on is using Chaco-3.2.0-py2.5-linux-x86_64.egg
> >
> > Thanks,
> > Rob
> > _______________________________________________
> > Enthought-Dev mailing list
> > [hidden email]
> > https://mail.enthought.com/mailman/listinfo/enthought-dev
> >
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev