ncl语言等高线图数值提取
时间: 2023-07-07 16:30:57 浏览: 209
等高线提取
在 NCL 中,可以使用 `cnFillOn` 和 `cnFillDraw` 函数来绘制等高线图。要提取等高线图上的数值,可以使用 `gsn_contour_labelbar` 函数来标注等高线上的数值。下面是一个示例代码:
```ncl
begin
; 读取示例数据
f = addfile("file.nc", "r")
data = f->data
; 绘制等高线图
res = True
res@cnFillOn = True
res@cnFillDraw = True
res@cnLinesOn = False
res@cnLevelSelectionMode = "ManualLevels"
res@cnMinLevelValF = -2.0
res@cnMaxLevelValF = 2.0
res@cnLevelSpacingF = 0.4
res@cnFillMode = "RasterFill"
res@cnRasterSmoothingOn = False
res@cnInfoLabelOn = False
res@tiMainString = "Contour plot"
plot = gsn_csm_contour_map(wks, data(0,:,:), res)
; 标注等高线上的数值
res_labelbar = True
res_labelbar@gsnDraw = False
res_labelbar@cnLabelBarOn = False
res_labelbar@cnLinesOn = False
res_labelbar@cnLineLabelsOn = True
res_labelbar@cnLineLabelFontHeightF = 0.01
res_labelbar@cnLineLabelPlacement = "Center"
res_labelbar@cnLineLabelDensityF = 0.5
res_labelbar@cnLineLabelBackgroundColor = "Transparent"
res_labelbar@cnLineLabelPerimOn = False
res_labelbar@cnLineLabelFontColor = "black"
res_labelbar@cnLineLabelFormat = "%.1f"
res_labelbar@lbLabelStrings = (/"-2.0","-1.6","-1.2","-0.8","-0.4","0.0","0.4","0.8","1.2","1.6","2.0"/)
gsn_contour_labelbar(plot, data(0,:,:), res_labelbar)
; 输出等高线上的数值
labels = plot@cnLineLabels
end
```
这个代码会绘制出一个等高线图,并在等高线上标注数值。你可以使用 `gsn_contour_labelbar` 函数的输出参数 `labels` 来获取标注的数值。如果需要将标注的数值保存到文件或变量中,可以使用 `labels` 变量。
阅读全文