Re: Multiple xy curves with different number of data points

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon, 6 Dec 2004 08:30:07 -0700

On Dec 5, 2004, at 1:42 PM, R. T. Pierrehumbert wrote:

> Here's a problem:
>
> I want to make an xy graph of two temperature soundings, on a common
> set of axes. The problem is that the first sounding has 100
> temperature
> and pressure points, but the second has only 20 (less data resolution).
> The axes and ranges are the same for both, though.
>
> As far as I can tell, the multiple-curve provisions for Ngl.xy require
> all the curves on a plot to have the same number of datapoints.
> So how can I get multiple curves on a plot, if they have different
> numbers of datapoints? Is there a standard way of doing this?
> Doing it using missing data codes would be a real mess.
>
> --Ray
>
> _______________________________________________
>

Ray,

There are a number of ways to do this. One way is to create both plots
as you normally would, using Ngl.xy, and then you overlay one on the
other. Here's a short example:

import Numeric
import Ngl

x = [10., 20.00, 30., 40.0, 50.000, 60.00, 70., 80.00, 90.000]
y = [ 0., 0.71, 1., 0.7, 0.002, -0.71, -1., -0.71, -0.003]
y2 = [ 0., -0.1, 0.5, 0.1, -0.7, -0.5]

wks_type = "x11"
wks = Ngl.open_wks(wks_type,"xy")

res1 = Ngl.Resources()
res2 = Ngl.Resources()

res1.xyLineColor = "red"
res2.xyLineColor = "blue"

plot1 = Ngl.xy(wks,x,y,res1)
plot2 = Ngl.xy(wks,x,y2,res2)

Ngl.overlay(plot1,plot2)
Ngl.draw(plot1)
Ngl.frame(wks)

Ngl.end()

Note that if your overlay plot (plot2 in this case) has any values that
fall outside the range of the values in
the base plot (plot1), then they will be clipped. That's because in an
overlay, the axes system of the base plot
is the one that's retained. If you don't want the first two plots drawn
just add:

res1.nglDraw = False
res1.nglFrame = False
res2.nglDraw = False
res2.nglFrame = False

There's another slightly more complicated method of using something
called NhlAddData, but I don't have a working
example of this yet. Using this method doesn't require that your
overlay plot be in the same dadta space; the axes
system will expand to encompass both.

--Mary

_______________________________________________
pyngl-talk mailing list
pyngl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/pyngl-talk
Received on Mon Dec 06 2004 - 08:30:07 MST

This archive was generated by hypermail 2.2.0 : Thu Jan 19 2006 - 21:30:17 MST