# [ncl-talk] slice plot

David Brown dbrown at ucar.edu
Thu Oct 2 15:56:26 MDT 2014

```Hi Bedassa,

You can't plot something with a 2D coordinate against a 1D coordinate in a
2D plot. The lon2d gives the longitude values for a horizontal 2D field.
You have to make some choices to get a vertical plot -- you need to reduce
the latitude dimension to a single element somehow. The simplest thing to
do would be to just pick one index along the y axis of the lon coordinate
-- e.g. lon2d(100,:). However, because the coordinates are 2d, the chances
are that this would not be a constant latitude, so you could not say for
instance that your plot represents height vs longitude at 10 degrees North
latitude.

But with proper labeling you could describe what this plot does represent.
I suggest you look at the NCL Examples page for Pressure/Height vs
Longitude plots and specifically at the last example on the page called
narr_6.ncl. It shows height plots for data where the coordinates are 2D
(aka "curvilinear" coordinates). Notice that the X axis for these plots has
both lat/lon values for the tickmark labels.This should give you some ideas
of what the issues are and how to solve them.

Creating a plot where the latitude is constant would require a bit more
work. But if you wanted to try you would probably want to use the function
getind_latlon2d. This might actually be a good topic for a future example.
-dave

On Wed, Oct 1, 2014 at 4:24 PM, Bedassa Regassa <beregassa at gmail.com> wrote:

> I am new to ncl. I am to plot the vertical Height vs longitude but I got
> warning and I tried to a lot to find my error.
>
> here is the wraning
>
> warning:ScalarFieldSetValues: 2d coordinate array sfXArray has an
> incorrect dimension size: defaulting sfXArray
>
> here is my data information ncl_filedump and below alos my scrip
>
> dimensions:
>       x = 186
>       y = 166
>       pressure = 9
>       time = 1  // unlimited
>       nb2 = 2
>    variables:
>       float lon ( y, x )
>          standard_name :        longitude
>          long_name :    longitude
>          units :        degrees_east
>          _CoordinateAxisType :  Lon
>
>       float lat ( y, x )
>          standard_name :        latitude
>          long_name :    latitude
>          units :        degrees_north
>          _CoordinateAxisType :  Lat
>
>       float pressure ( pressure )
>          standard_name :        air_pressure
>          long_name :    pressure
>          units :        Pa
>          positive :     down
>          axis : Z
>
>       double time ( time )
>          standard_name :        time
>          long_name :    time
>          bounds :       time_bnds
>          units :        seconds since 2009-05-01 00:00:00
>          calendar :     proleptic_gregorian
>
>       double time_bnds ( time, nb2 )
>          units :        seconds since 2009-05-01 00:00:00
>          calendar :     proleptic_gregorian
>
>  float U ( time, pressure, y, x )
>          standard_name :        grid_eastward_wind
>          long_name :    U-component of wind
>          units :        m s-1
>          coordinates :  lon lat
>
> ;************************************************
> ;************************************************
> ;************************************************
> begin
> ;************************************************
> ;open file and read in data
> ;************************************************
> ;************************************************
> ; get variables infromation and print them  cclm
> ;************************************************
> vars = getfilevarnames(f)
> print(vars)
> ;************************************************
> var=f->U(0,:,15,:)
> lon2d=f->lon
> lev=f->pressure
>
> var at lon2d=lon2d
> var at lev=lev
> ;*******************************
> ;create plot
> ;************************************************
>
> ;-- define workstation
> wks = gsn_open_wks("png","plot_slices")
> gsn_define_colormap(wks,"ncl_default") ;-- set the colormap to be used
> ;-- set resources
> res = True
> res at tiMainString = "DKRZ NCL Tutorial Example: Slice plot at 40N"
> res at cnFillOn = True ;-- turn on color fill
> res at cnLineLabelsOn = False ;-- turns off contour line labels
> res at cnInfoLabelOn = False ;-- turns off contour info label
> res at lbOrientation = "vertical" ;-- vertical label bar
> res at tiYAxisString = var at long_name+" [hPa]"
> ;-- append units to y-axis label
> ;res at tfDoNDCOverlay = True
> res at sfXArray = lon2d ;-- uses lon_t as plot x-axis
> res at sfYArray = lev/100 ;-- uses lev_t in hPa as plot y-axis
> res at gsnYAxisIrregular2Linear = True ;-- converts irreg depth to linear
> res at trYReverse = True ;-- reverses y-axis
>
> ;-- generate the plot
> plot = gsn_csm_contour(wks,var,res)
> end
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20141002/ce5116e0/attachment.html
```