NCL 绘图:将 PNG 文件保存到当前目录

load '$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl'

begin
    a = addfile('geo_em.d01.nc','r') ; Open a file
    
    type = 'png'
    wks = gsn_open_wks(type,'./plt_geo_1')  ; 将输出文件保存到当前目录
    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

end

解释:

  • gsn_open_wks 函数用于打开一个图形输出设备。第一个参数是输出文件的类型,第二个参数是输出文件名或路径。
  • 在代码中,将 wks = gsn_open_wks(type,'./plt_geo_1') 修改为 wks = gsn_open_wks(type,'plt_geo_1'),将输出文件保存到当前目录下。
  • ./ 表示当前目录,你可以根据需要修改文件名和路径。

注意:

  • 确保 NCARG_ROOT 环境变量已设置。
  • 修改代码中的文件名和路径,以适应你的需求。

通过以上修改,你可以将 NCL 生成的 PNG 图像文件保存到当前目录。

NCL 绘图:将 PNG 文件保存到当前目录

原文地址: https://www.cveoy.top/t/topic/o8cb 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录