- 积分
- 9007
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2017-2-27
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 里斯斯里 于 2019-8-13 19:18 编辑
NCL在添加文本到图形上有两个函数:gsn_add_text和gan_text_ndc,两个函数在但单独用到一张图片的时候都挺好使的,
但想在组图的固定位置(NCL的NDC坐标)上添加文本的时候,gsn_text_ndc(wks, text, x, y, res)无法指定某张图片进行添加且在组图中的位置难以确定!
自己写的一个函数来对组图中的单独一张图片固定位置添加文本: - undef("Overlay_Coefficient")
- procedure Overlay_Coefficient( wks, BasePlot:graphic, Var_X[*]:numeric, Var_Y[*]:numeric )
- local txres, R, str, vpx, vpy, vpw, vph, pos
- begin
- ;--- Add the regression coeffecient
- txres = True
- txres@txFontColor = "red"
- txres@txFontHeightF = 0.01
- R = escorc(Var_X, Var_Y)
- str = unique_string("text")
- getvalues BasePlot
- "vpXF" : vpx
- "vpYF" : vpy
- "vpWidthF" : vpw
- "vpHeightF" : vph
- end getvalues
- pos = (/vpx+0.3*vpw, vpy-0.15*vph/)
- ; print(pos)
- ; BasePlot@$str$ = gsn_add_text(wks, BasePlot, "R="+sprintf("%4.2f", R), min(Var_X)*0.7, max(Var_Y)*0.85, txres)
- gsn_text_ndc(wks, "R="+sprintf("%4.2f", R), pos(0), pos(1), txres)
- end
复制代码
其中需要注意的是,在这一步之前已经执行过gsn_panel程序
代码如下:
- pres = True
- pres@gsnFrame = False
- pres@gsnMaximize = True
- pres@gsnPanelFigureStrings = (/"(a)","(b)","(c)","(d)","(e)","(f)","(g)","(h)","(i)","(j)","(k)","(l)"/)
- pres@gsnPanelFigureStringsJust = "TopLeft"
- pres@gsnPanelFigureStringsFontHeightF = 0.008
- pres@gsnPanelBottom = 0.04 ;--- move panel top to give space for bottom strings.
- pres@gsnPanelXWhiteSpacePercent = 15 ;--- the distance between plots elembers(X)
- pres@gsnPanelYWhiteSpacePercent = 3 ;--- the distance between plots elembers(Y)
- pres@gsnPanelSave = True
- ; gsn_panel(wks, ndtooned((/plots_diff_Avg, plots_pct_Avg/)), (/2,3/), pres)
- gsn_panel(wks, Plots, (/3,2/), pres)
复制代码 重要的是最后一个属性pres@gsnPanelSave = True,必须打开才有用。
最终图片效果如下(原谅我粗犷的审美):
另外画图中碰到过几个问题总结一下:
Q1:画组图时由于多张图片都在一页上,会出现部分图片超出去看不见了
解决方法:调整gsn_panel的这个属性试试 gsnPanelBottom,gsnPanelTop,gsnPanelLeft,gsnPanelRight,这四个属性分别是给图片上留空白空间用的(上下左右)。我的情况就是最下面的一行图片坐标不见了,设置gsnPanelBottom = 0.04就好了。
Q2:调整组图各张图片之间的间距?
解决方法:使用gsnPanelXWhiteSpacePercent 和gsnPanelYWhiteSpacePercent这个两个属性
这些事画图时候自己的一些想法,欢迎多多给点意见。
参考帖子:
http://www.ncl.ucar.edu/Applications/Scripts/panel_GWLs_Rain.ncl
|
评分
-
查看全部评分
|