Free rotation of Chaco plots

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

Free rotation of Chaco plots

Brennan Sellner
Hi,

Is there any way to freely rotate Chaco plots?  In part of our
application, we use a mixture of LinePlots and ScatterPlots to display
data tied to physical locations in an XY plane.  While exploring the
plot, it would be useful to allow the user to freely rotate it (e.g. to
align some portion of the data with the long dimension of their
monitor).  I've been digging around in the Chaco documentation, and I'm
not finding anything relevant.  It seems like we should be able to
define a single transform that's applied before any drawing occurs, but
I haven't had much luck.

Am I on a wild goose chase, or is this doable with Chaco?

Thanks,

-Brennan

---

My apologies for the below:
Email Confidentiality Notice

The information contained in this transmission is confidential, proprietary or privileged and may be subject to protection under the law. This message is intended for the sole use of the individual or entity to whom it's addressed. If you are not the intended recipient, you are notified that any use, distribution or copying of the message is strictly prohibited and may subject you to criminal or civil penalties. If you received this transmission in error, please contact the sender immediately by replying to this email and delete the material from any computer.
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Free rotation of Chaco plots

Jake Ross
Hi Brennan

You want to apply a transformation to the GraphicContext ctm using translate_ctm(x,y) and rotate_ctm(rad)

here is an example of a rotatable plot container. Its not interactive but it should be easy to connect to a trait or chaco tool. 

class RotatablePlotContainer(OverlayPlotContainer):

    rotation = Float(0)  # rotation in degrees

    def _draw(self, gc, *args, **kw):

        w2 = self.width / 2

h2 = self.height / 2

        gc.translate_ctm(w2, h2)

        gc.rotate_ctm(math.radians(self.rotation))

        gc.translate_ctm(-w2, -h2)

        super(RotatablePlotContainer, self)._draw(gc, *args, **kw)



On Tue, Jun 11, 2013 at 3:51 PM, Brennan Sellner <[hidden email]> wrote:
Hi,

Is there any way to freely rotate Chaco plots?  In part of our
application, we use a mixture of LinePlots and ScatterPlots to display
data tied to physical locations in an XY plane.  While exploring the
plot, it would be useful to allow the user to freely rotate it (e.g. to
align some portion of the data with the long dimension of their
monitor).  I've been digging around in the Chaco documentation, and I'm
not finding anything relevant.  It seems like we should be able to
define a single transform that's applied before any drawing occurs, but
I haven't had much luck.

Am I on a wild goose chase, or is this doable with Chaco?

Thanks,

-Brennan

---

My apologies for the below:
Email Confidentiality Notice

The information contained in this transmission is confidential, proprietary or privileged and may be subject to protection under the law. This message is intended for the sole use of the individual or entity to whom it's addressed. If you are not the intended recipient, you are notified that any use, distribution or copying of the message is strictly prohibited and may subject you to criminal or civil penalties. If you received this transmission in error, please contact the sender immediately by replying to this email and delete the material from any computer.
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev



--
Jake Ross
NM Tech
[hidden email]
[hidden email]
575-835-5994 (office)

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

Re: Free rotation of Chaco plots

Jake Ross

class RotatablePlotContainer(OverlayPlotContainer):
    rotation = Float(0)  # rotation in degrees
    def _draw(self, gc, *args, **kw):
        w2 = self.width / 2
        h2 = self.height / 2
        gc.translate_ctm(w2, h2)
        gc.rotate_ctm(math.radians(self.rotation))
        gc.translate_ctm(-w2, -h2)
        super(RotatablePlotContainer, self)._draw(gc, *args, **kw)

This rotates the entire plot container, axis and data around the center of the plot. 


On Sat, Jun 15, 2013 at 9:42 AM, Jake Ross <[hidden email]> wrote:
Hi Brennan

You want to apply a transformation to the GraphicContext ctm using translate_ctm(x,y) and rotate_ctm(rad)

here is an example of a rotatable plot container. Its not interactive but it should be easy to connect to a trait or chaco tool. 

class RotatablePlotContainer(OverlayPlotContainer):

    rotation = Float(0)  # rotation in degrees

    def _draw(self, gc, *args, **kw):

        w2 = self.width / 2

h2 = self.height / 2

        gc.translate_ctm(w2, h2)

        gc.rotate_ctm(math.radians(self.rotation))

        gc.translate_ctm(-w2, -h2)

        super(RotatablePlotContainer, self)._draw(gc, *args, **kw)



On Tue, Jun 11, 2013 at 3:51 PM, Brennan Sellner <[hidden email]> wrote:
Hi,

Is there any way to freely rotate Chaco plots?  In part of our
application, we use a mixture of LinePlots and ScatterPlots to display
data tied to physical locations in an XY plane.  While exploring the
plot, it would be useful to allow the user to freely rotate it (e.g. to
align some portion of the data with the long dimension of their
monitor).  I've been digging around in the Chaco documentation, and I'm
not finding anything relevant.  It seems like we should be able to
define a single transform that's applied before any drawing occurs, but
I haven't had much luck.

Am I on a wild goose chase, or is this doable with Chaco?

Thanks,

-Brennan

---

My apologies for the below:
Email Confidentiality Notice

The information contained in this transmission is confidential, proprietary or privileged and may be subject to protection under the law. This message is intended for the sole use of the individual or entity to whom it's addressed. If you are not the intended recipient, you are notified that any use, distribution or copying of the message is strictly prohibited and may subject you to criminal or civil penalties. If you received this transmission in error, please contact the sender immediately by replying to this email and delete the material from any computer.
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev



--
Jake Ross
NM Tech
[hidden email]
[hidden email]
<a href="tel:575-835-5994" value="+15758355994" target="_blank">575-835-5994 (office)



--
Jake Ross
NM Tech
[hidden email]
[hidden email]
575-835-5994 (office)

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

Re: Free rotation of Chaco plots

Brennan Sellner
On 06/15/2013 11:47 AM, Jake Ross wrote:

>
> class RotatablePlotContainer(OverlayPlotContainer):
>     rotation = Float(0)  # rotation in degrees
>     def _draw(self, gc, *args, **kw):
>         w2 = self.width / 2
>         h2 = self.height / 2
>         gc.translate_ctm(w2, h2)
>         gc.rotate_ctm(math.radians(self.rotation))
>         gc.translate_ctm(-w2, -h2)
>         super(RotatablePlotContainer, self)._draw(gc, *args, **kw)
>
> This rotates the entire plot container, axis and data around the center
> of the plot.
Thanks, Jake!  I had been focusing on the individual plots, and didn't
think to look at the container.  However, in my experimentation, if
self.rotation is set to any non-zero value, this crashes kiva while it's
clipping the grid:

(Pdb)
> /usr/lib/python2.7/dist-packages/chaco/grid.py(335)_draw_component()
-> gc.clip_to_rect(*(self.component.position + self.component.bounds))

(Pdb)
--Call--
> /usr/lib/python2.7/dist-packages/kiva/agg/agg.py(1008)clip_to_rect()
-> def clip_to_rect(self, *args): return
_agg.GraphicsContextArray_clip_to_rect(self, *args)

(Pdb)
> /usr/lib/python2.7/dist-packages/kiva/agg/agg.py(1008)clip_to_rect()
-> def clip_to_rect(self, *args): return
_agg.GraphicsContextArray_clip_to_rect(self, *args)

(Pdb)
Qt has caught an exception thrown from an event handler. Throwing
exceptions from an event handler is not supported in Qt. You must
reimplement QApplication::notify() and catch all exceptions there.

terminate called after throwing an instance of 'kiva::._178'

This is from running the attached script (a slight modification of
qt_example.py), with the following library versions:

>>> import chaco
>>> chaco.__version__
'4.2.0'
>>> import PySide
>>> PySide.__version__
'1.1.2'
>>> import sys
>>> sys.version
'2.7.3 (default, Aug  1 2012, 05:14:39) \n[GCC 4.6.3]'

Before I go digging further, is this a problem for you, or is it perhaps
localized to my system?  Any off-the-cuff suggestions from anyone?

Thanks!

-Brennan

---

My apologies for the below:

Email Confidentiality Notice

The information contained in this transmission is confidential, proprietary or privileged and may be subject to protection under the law. This message is intended for the sole use of the individual or entity to whom it's addressed. If you are not the intended recipient, you are notified that any use, distribution or copying of the message is strictly prohibited and may subject you to criminal or civil penalties. If you received this transmission in error, please contact the sender immediately by replying to this email and delete the material from any computer.

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

qt_example_rotating.py (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Free rotation of Chaco plots

Fred

>Le 17/06/2013 04:56, Brennan Sellner a écrit :
> On 06/15/2013 11:47 AM, Jake Ross wrote:
>>
>> class RotatablePlotContainer(OverlayPlotContainer):
>>     rotation = Float(0)  # rotation in degrees
>>     def _draw(self, gc, *args, **kw):
>>         w2 = self.width / 2
>>         h2 = self.height / 2
>>         gc.translate_ctm(w2, h2)
>>         gc.rotate_ctm(math.radians(self.rotation))
>>         gc.translate_ctm(-w2, -h2)
>>         super(RotatablePlotContainer, self)._draw(gc, *args, **kw)
>>
>> This rotates the entire plot container, axis and data around the center
>> of the plot.
>
> Thanks, Jake!  I had been focusing on the individual plots, and didn't
> think to look at the container.  However, in my experimentation, if
> self.rotation is set to any non-zero value, this crashes kiva while it's
> clipping the grid:
Hi Brennan,

Get the same issue here.

Slightly modified cmap_scatter.py attached showing the issue.

BTW, the colorbar is at the left of the plot, instead of the right, as
it should be.

TIA


Cheers,

--
Fred

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

cmap_scatter.py (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Free rotation of Chaco plots

Jake Ross
Had me stumped for a while but I finally made a working rotated plot container for qt.

I am using a PlotContainer and had to set use_backbuffer=True otherwise Python would crash as described previously. 

see attached for working example

HTH
-J
 


On Mon, Jun 17, 2013 at 2:09 AM, Fred <[hidden email]> wrote:

>Le 17/06/2013 04:56, Brennan Sellner a écrit :
> On 06/15/2013 11:47 AM, Jake Ross wrote:
>>
>> class RotatablePlotContainer(OverlayPlotContainer):
>>     rotation = Float(0)  # rotation in degrees
>>     def _draw(self, gc, *args, **kw):
>>         w2 = self.width / 2
>>         h2 = self.height / 2
>>         gc.translate_ctm(w2, h2)
>>         gc.rotate_ctm(math.radians(self.rotation))
>>         gc.translate_ctm(-w2, -h2)
>>         super(RotatablePlotContainer, self)._draw(gc, *args, **kw)
>>
>> This rotates the entire plot container, axis and data around the center
>> of the plot.
>
> Thanks, Jake!  I had been focusing on the individual plots, and didn't
> think to look at the container.  However, in my experimentation, if
> self.rotation is set to any non-zero value, this crashes kiva while it's
> clipping the grid:
Hi Brennan,

Get the same issue here.

Slightly modified cmap_scatter.py attached showing the issue.

BTW, the colorbar is at the left of the plot, instead of the right, as
it should be.

TIA


Cheers,

--
Fred

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




--
Jake Ross
NM Tech
[hidden email]
[hidden email]
575-835-5994 (office)

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

rotated_graphic_generator.py (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Free rotation of Chaco plots

Didrik Pinte-2
Hi Jake,

Thanks for the report. It would be great if you could report the bug
on github to make sure it gets traced and solved as soon as we can.

Thanks,

-- Didrik

On 18 June 2013 08:09, Jake Ross <[hidden email]> wrote:

> Had me stumped for a while but I finally made a working rotated plot
> container for qt.
>
> I am using a PlotContainer and had to set use_backbuffer=True otherwise
> Python would crash as described previously.
>
> see attached for working example
>
> HTH
> -J
>
>
>
> On Mon, Jun 17, 2013 at 2:09 AM, Fred <[hidden email]> wrote:
>>
>>
>> >Le 17/06/2013 04:56, Brennan Sellner a écrit :
>> > On 06/15/2013 11:47 AM, Jake Ross wrote:
>> >>
>> >> class RotatablePlotContainer(OverlayPlotContainer):
>> >>     rotation = Float(0)  # rotation in degrees
>> >>     def _draw(self, gc, *args, **kw):
>> >>         w2 = self.width / 2
>> >>         h2 = self.height / 2
>> >>         gc.translate_ctm(w2, h2)
>> >>         gc.rotate_ctm(math.radians(self.rotation))
>> >>         gc.translate_ctm(-w2, -h2)
>> >>         super(RotatablePlotContainer, self)._draw(gc, *args, **kw)
>> >>
>> >> This rotates the entire plot container, axis and data around the center
>> >> of the plot.
>> >
>> > Thanks, Jake!  I had been focusing on the individual plots, and didn't
>> > think to look at the container.  However, in my experimentation, if
>> > self.rotation is set to any non-zero value, this crashes kiva while it's
>> > clipping the grid:
>> Hi Brennan,
>>
>> Get the same issue here.
>>
>> Slightly modified cmap_scatter.py attached showing the issue.
>>
>> BTW, the colorbar is at the left of the plot, instead of the right, as
>> it should be.
>>
>> TIA
>>
>>
>> Cheers,
>>
>> --
>> Fred
>>
>> _______________________________________________
>> Enthought-Dev mailing list
>> [hidden email]
>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>>
>
>
>
> --
> Jake Ross
> NM Tech
> [hidden email]
> [hidden email]
> 575-835-5994 (office)
>
> _______________________________________________
> 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: Free rotation of Chaco plots

Fred
In reply to this post by Jake Ross
Le 18/06/2013 08:09, Jake Ross a écrit :
> Had me stumped for a while but I finally made a working rotated plot
> container for qt.
>
> I am using a PlotContainer and had to set use_backbuffer=True otherwise
> Python would crash as described previously.
>
> see attached for working example

I still have crash with use_backbuffer=True in my example... :-/

> HTH
> -J
>  
>
>
> On Mon, Jun 17, 2013 at 2:09 AM, Fred <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>
>     >Le 17/06/2013 04:56, Brennan Sellner a écrit :
>     > On 06/15/2013 11:47 AM, Jake Ross wrote:
>     >>
>     >> class RotatablePlotContainer(OverlayPlotContainer):
>     >>     rotation = Float(0)  # rotation in degrees
>     >>     def _draw(self, gc, *args, **kw):
>     >>         w2 = self.width / 2
>     >>         h2 = self.height / 2
>     >>         gc.translate_ctm(w2, h2)
>     >>         gc.rotate_ctm(math.radians(self.rotation))
>     >>         gc.translate_ctm(-w2, -h2)
>     >>         super(RotatablePlotContainer, self)._draw(gc, *args, **kw)
>     >>
>     >> This rotates the entire plot container, axis and data around the
>     center
>     >> of the plot.
>     >
>     > Thanks, Jake!  I had been focusing on the individual plots, and didn't
>     > think to look at the container.  However, in my experimentation, if
>     > self.rotation is set to any non-zero value, this crashes kiva
>     while it's
>     > clipping the grid:
>     Hi Brennan,
>
>     Get the same issue here.
>
>     Slightly modified cmap_scatter.py attached showing the issue.
>
>     BTW, the colorbar is at the left of the plot, instead of the right, as
>     it should be.
>
>     TIA
>
>
>     Cheers,
>
>     --
>     Fred
>
>     _______________________________________________
>     Enthought-Dev mailing list
>     [hidden email]
>     <mailto:[hidden email]>
>     https://mail.enthought.com/mailman/listinfo/enthought-dev
>
>
>
>
> --
> Jake Ross
> NM Tech
> [hidden email] <mailto:[hidden email]>
> [hidden email] <mailto:[hidden email]>
> 575-835-5994 (office)
>
>
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev


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