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

在使用 NCL 绘制图形时,有时需要将输出的 PNG 文件保存到当前目录。你可以使用 NCL 内置的系统变量 cwd 来获取当前工作目录,并将其添加到 wkOutputFilePath 中。

以下是如何修改代码以将输出的 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
    setvalues plot, (/ 'wkOutputFilePath': (cwd+'/abc.png') /)
end

这将把输出的 PNG 文件保存到当前目录下的 abc.png 文件中。

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

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

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