multi-axis plot question

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

multi-axis plot question

Edward Wen

Hi,

 

I’m pretty new to this stuff.  Does anyone know how to plot on the same plot two lines that have different y-axis but the same x-axis.  I’m using a Plot on a ArrayplotData

 

arrayPlotData = ArrayPlotData()

plotcontainer = Plot(arrayPlotData)

 

arrayPlotData.set_data(name=’A’, new_data=(data1))

arrayPlotData.set_data(name=’B’, new_data=(data2))

arrayPlotData.set_data(name=’ts’, new_data=(ts))

arrayPlotData.set_data(name=’ts2’, new_data=(ts2))

 

plotcontainer.plot(("ts", ‘A’), name=’A’, type="scatter", color='blue', marker ='triangle', size = 3)

plotcontainer.plot(("ts2", ‘B’),name=’B’, type="line", color=red)

 

but I want A and B to plot on different y-axis but the same x-axis.  I also tried adding another plot to the container using create_line_plot instead, but I couldn’t get the time-stamps to line up. 

 

Much thanks, Ed

 

 



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.


GETCO Europe Limited is a wholly-owned subsidiary of GETCO Holding Company, and is a company registered in England and Wales with Company Number 4663084 and registered office at 2nd floor, Vintners Place, 68 Upper Thames Street, London, EC4V 3BJ. GETCO Europe Limited is authorised and regulated by the Financial Services Authority.

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

Re: multi-axis plot question

Peter Wang
On Fri, Oct 29, 2010 at 12:26 PM, Edward Wen <[hidden email]> wrote:

> I’m pretty new to this stuff.  Does anyone know how to plot on the same plot
> two lines that have different y-axis but the same x-axis.  I’m using a Plot
> on a ArrayplotData
> arrayPlotData = ArrayPlotData()
> plotcontainer = Plot(arrayPlotData)
> arrayPlotData.set_data(name=’A’, new_data=(data1))
> arrayPlotData.set_data(name=’B’, new_data=(data2))
> arrayPlotData.set_data(name=’ts’, new_data=(ts))
> arrayPlotData.set_data(name=’ts2’, new_data=(ts2))
>
> plotcontainer.plot(("ts", ‘A’), name=’A’, type="scatter", color='blue',
> marker ='triangle', size = 3)
>
> plotcontainer.plot(("ts2", ‘B’),name=’B’, type="line", color=red)
>
> but I want A and B to plot on different y-axis but the same x-axis.

There are several ways to do this.  An individual Plot object is just
an OverlayPlotContainer with well defined X and Y mappers and axes
that it automatically sets on all renderers created via its .plot()
method.  There is nothing to prevent you from treating it as a plain
container, and adding new renderers to it that were created with the
create_line_plot() or create_scatter_plot() convenience functions.

You can look at the multiaxis_using_Plot.py example to see how to add
a new line plot, created via create_line_plot, to an existing Plot,
and adding separate X and Y axes:
https://svn.enthought.com/enthought/browser/Chaco/trunk/examples/multiaxis_using_Plot.py

Now, if you want the second plot to share the same horizontal axis as
the Plot, then it might be easier to just ask the Plot to create a
second plot, but manually create a separate mapper and axis for it:

    from enthought.chaco.api import DataRange1D, LinearMapper,
PlotAxis, PlotGrid
    # Need to use[0] because plot() returns a list of renderers
    plot2 = plot1.plot(("index", "y1"), name="j_1", color="blue")[0]
    plot2.value_mapper = LinearMapper(range=DataRange1D(plot2.value))
    # This is important, because otherwise the left axis, when auto-scaling,
    # will also take into account plot2's Y values
    plot1.value_range.remove(plot2.value)
    # Create a new axis, tell it that it will be on the right side of the plot,
    # and add it to plot1
    yaxis2 = PlotAxis(orientation="right", mapper=plot2.value_mapper,
component=plot1)
    plot1.overlays.append(yaxis2)

Additionally, there is some work that has to be done with the tools.
In order to get events to both plots, a BroadcasterTool; however, this
duplicates the horizontal pan event, so we have to tell the PanTool on
the second plot that it should only modify the Y-axis of the plot.
(The X axis changes are handled by the PanTool on plot1.)

    broadcaster = BroadcasterTool()
    broadcaster.tools.append(PanTool(plot1))
    broadcaster.tools.append(PanTool(plot2, constrain=True,
constrain_direction="y"))

A similar thing then has to be done for the zoom tool.

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

making pdfs

Edward Wen
In reply to this post by Edward Wen

Hi,

 

This question related to Jim Radke’s question about saving plots as pdfs.  Does the same syntax work with VPlotContainer.  When I try to render and save a VplotContainer, they show up on top of each other. 

 

-Ed

 



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.


GETCO Europe Limited is a wholly-owned subsidiary of GETCO Holding Company, and is a company registered in England and Wales with Company Number 4663084 and registered office at 2nd floor, Vintners Place, 68 Upper Thames Street, London, EC4V 3BJ. GETCO Europe Limited is authorised and regulated by the Financial Services Authority.

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

Re: making pdfs

Peter Wang
On Tue, Nov 16, 2010 at 1:21 PM, Edward Wen <[hidden email]> wrote:
> Hi,
> This question related to Jim Radke’s question about saving plots as pdfs.
> Does the same syntax work with VPlotContainer.  When I try to render and
> save a VplotContainer, they show up on top of each other.

You shouldn't have to do anything terribly different, but there does
seem to be an issue with regards to sizing and layout.  I'm looking
into it..

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

Re: making pdfs

Peter Wang
Ed,

I have fixed the problem.  It turns out to have been a pretty simple
error in the PdfGraphicsContext.  Please either apply the following
patch to your copy of chaco/pdf_graphics_context.py, or download the
new version from our tracker and place it into your installed version
of Chaco: https://svn.enthought.com/enthought/export/26012/Chaco/trunk/enthought/chaco/plot_graphics_context.py

-Peter

Index: pdf_graphics_context.py
===================================================================
--- pdf_graphics_context.py     (revision 25991)
+++ pdf_graphics_context.py     (working copy)
@@ -155,10 +155,10 @@

             self.translate_ctm(trans_x, trans_y)
             self.scale_ctm(scale, scale)
-            self.clip_to_rect(0, 0, trans_width, trans_height)
+            self.clip_to_rect(0, 0, width, height)
             old_bb_setting = component.use_backbuffer
             component.use_backbuffer = False
-            component.draw(self, view_bounds=(0, 0, trans_width, trans_height))
+            component.draw(self, view_bounds=(0, 0, width, height))
             component.use_backbuffer = old_bb_setting
             return


On Tue, Nov 16, 2010 at 10:12 PM, Peter Wang <[hidden email]> wrote:

> On Tue, Nov 16, 2010 at 1:21 PM, Edward Wen <[hidden email]> wrote:
>> Hi,
>> This question related to Jim Radke’s question about saving plots as pdfs.
>> Does the same syntax work with VPlotContainer.  When I try to render and
>> save a VplotContainer, they show up on top of each other.
>
> You shouldn't have to do anything terribly different, but there does
> seem to be an issue with regards to sizing and layout.  I'm looking
> into it..
>
> -Peter
>
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev