NCL折线图

本文介绍了如何使用NCL(NCAR Command Language)来创建折线图,包括标题、坐标轴的设置以及多根折线和图例的处理。通过示例脚本和执行过程,展示了NCL在图形绘制上的应用。

一、NCL标题及坐标轴设置

1、首先定义好文件目录,比如程序存放目录和文件输出目录

2、开始编写程序:写法和我之前用的语言大同小异

begin
  npts = 500
  y = 500.+.9* ispan(0,npts-1,1)*sin(0.031415926535898*ispan(0,npts-1,1))
  y1=ispan(0,npts-1,1)                     ;这个画出来的图就是y=x

  wks = gsn_open_wks("png","/cygdrive/d/learn/ncl-test/output/ex_title")  

  res = True     
  res@tiMainString="ex_titl"   ;添加图片主题
  res@tiMainFontHeightF=0.05                     ;主题字体大小
  res@tiMainFontColor="red"                      ;主题字体颜色
  res@gsnCenterString="center title"
  res@gsnLeftString="left title"
  res@gsnRightString="right title"

  res@tiXAxisString="X axis"
  res@tiYAxisString="Y axis"
  res@tiXAxisFontColor="black"
  
  
  plot = gsn_csm_y(wks,y,res)
end

3、执行脚本: 

ncl /cygdrive/d/learn/ncl-test/script-upload/ex_title.ncl

 

4、在d/learn/ncl-test/output文件下会出现title1_ex.png,如图:

 

 

二、多根折线及图例


begin
 npts = 500
 x    = fspan(-100,100,npts)  ;创建一个从-100到100的500个数值的等差数列
 y    = new((/4,500/),"float")
 y(0,:) =sin(0.0628*x)
 y(1,:) =cos(0.0628*x) 
 y(2,:) =cos(0.0628*x)*sin(0.0628*x)
 y(3,:) =cos(0.0628*x)+sin(0.0628*x)

 wks=gsn_open_wks("png", "/cygdrive/d/learn/ncl-test/output/xyLengend")


 res = True

 res@trXMinF = min(x)
 res@trXMaxF = max(x)
 res@trYMinF = min(y) - 0.2
 res@trYMaxF = max(y) + 0.6

 res@xyLineThicknesses = (/1,2,3,4/)
 res@xyLineColors    = (/"black","HotPink","OrangeRed","Green"/)  ;line color
 res@xyDashPatterns    =(/0,2,4,6/)                                 ;differ lines

 res@pmLegendDisplayMode    = "Always"                              ;add lengend
 res@xyExplicitLegendLabels = (/"tem","rhu","wind","AQI"/)          ;lengend title by english
 res@pmLegendWidthF         = 0.2                                   ;lengend width
 res@pmLegendHeightF        = 0.1                                   ;lengend height

 res@pmLegendOrthogonalPosF  = -1.05                                ;
 res@pmLegendParallelPosF    = 0.82
 
 plot = gsn_csm_xy(wks,x,y,res)

end

 执行:

ncl /cygdrive/d/learn/ncl-test/script-upload/ex_xy_lengend.ncl

输出:

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值