Re: Draw trend line in xy plot

From: Will Hobbs <Will.Hobbs_at_nyahnyahspammersnyahnyah>
Date: Fri Dec 14 2012 - 18:20:10 MST

Ronny

Below is an answer I posted yesterday to ncl-talk to pretty much exactly the same question…….

Soumik

There are several ways you could do this: if you're modifying an existing
script then the first is probably easiest.

1. Draw the trends as polylines:
http://www.ncl.ucar.edu/Applications/polyg.shtml

2. Calculate 'synthetic' data points using regline, and plot them as a
regular xy plot .e.g. for a 1-d array, x:

xAll = new((/2,dimsizes(x)/), typeof(x)) ;new array for data
xAll(0,:) = x ; add raw data to array

reg = regline(time,x)

xAll(1,:) = reg@yintercept + (time * reg) ;points along a trend line
for each time step

plot = gsn_csm_xy(wks, time, xAll, res) ; will plot two lines, a trend
and the raw data

Will

From: Ronny Berndt <ronny.berndt@uni-jena.de<mailto:ronny.berndt@uni-jena.de>>
Date: Friday, 14 December 2012 11:35 PM
To: "ncl-talk@ucar.edu<mailto:ncl-talk@ucar.edu>" <ncl-talk@ucar.edu<mailto:ncl-talk@ucar.edu>>
Subject: Draw trend line in xy plot

Hi,

I want to draw a trend line in a xy plot. I have these variables:

x ... years
v ... y - data field(0..3) (for 4 lines)
trend ... trend=dtrend_msg(x,v,True,True)

Variable: x
Type: integer
Total Size: 164 bytes
            41 values
Number of Dimensions: 1
Dimensions and sizes: [41]
Coordinates:
Number Of Attributes: 1
  units : years

Variable: v
Type: float
Total Size: 656 bytes
            164 values
Number of Dimensions: 2
Dimensions and sizes: [4] x [41]
Coordinates:
Number
Of Attributes: 2
  units : temperature [~F34~0~F21~C]
  _FillValue : 9.96921e+36

Variable: trend
Type: float
Total Size: 656 bytes
            164 values
Number of Dimensions: 2
Dimensions and sizes: [4] x [41]
Coordinates:
Number Of Attributes: 3
  _FillValue : 9.96921e+36
  y_intercept : ( -21.39967, -19.16433, -16.27571, -24.15463 )
  slope : ( 0.02267744, 0.02084449, 0.01997482, 0.02466693 )

Now i want to plot these 4 trend lines into the map.
what do i have to do to plot these trend lines?

I attached the ncl-file and the nc file.

Cheers,
Ronny

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Dec 14 18:20:24 2012

This archive was generated by hypermail 2.1.8 : Fri Dec 21 2012 - 10:43:23 MST