NCL 绘制等值线图并保存到当前目录
load '$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl'
begin a = addfile('geo_em.d01.nc','r') ; Open a file
type = 'png'
output_dir = './' ; 设置输出文件的路径为当前目录
output_filename = 'plt_geo_1.png' ; 设置输出文件的名称
wks = gsn_open_wks(type,output_filename) ; 打开输出文件
ter = a->HGT_M(0,:,:)
res = True ; Create plot resource variable
res@cnFillOn = True ; Enable filled contours
res@gsnSpreadColors = True ; Use color spread across the entire color map
plot = gsn_contour(wks,ter,res) ; Create plot
frame(wks) ; 输出最终图形
delete(wks) ; 关闭输出文件
end
在上述代码中,output_dir变量被设置为当前目录,output_filename变量被设置为plt_geo_1.png。然后,gsn_open_wks函数被调用时,将output_filename作为第二个参数传递给函数,从而将输出文件的路径和名称设置为当前目录下的plt_geo_1.png文件。最后,通过frame函数输出最终的图形,并通过delete函数关闭输出文件。
原文地址: https://www.cveoy.top/t/topic/o8ca 著作权归作者所有。请勿转载和采集!