爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 190|回复: 3

[作图] ncl画散点图

[复制链接]

新浪微博达人勋

发表于 2025-1-5 16:20:46 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
本帖最后由 无敌大壮壮 于 2025-1-5 16:22 编辑
  1. f=readAsciiTable("20210720120000.txt",5,"float",1);读取文本文件,这种读取方式可以跳过表头,后面那个的意思是表头占的行数
  2. data=f(:,:);把数据取出来
  3. lat=data(:,1)
  4. lon=data(:,2)
  5. pre1=data(:,4)

  6. lat@_FillValue=999990
  7. lon@_FillValue=999990
  8. pre1@_FillValue=999990
  9. pre1(ind(ismissing(pre1))) = 0 ; ind将a中为缺省值的数组索引去除,并将其中对应缺省值的元素赋值为0

  10. ; lat1 = where(lat.lt. 31.and.lat.gt. 37,lat@_FillValue,lat)
  11. ; lon1 = where(lon.lt.110.and.lon.gt.117,lon@_FillValue,lon)
  12. ;;;d = ind(pre1.le.50.and.pre1.gt.0)   ;;;;返回满足这个条件中pre1的索引
  13. lat1 = lat(ind(lat.lt. 36.and.lat.gt. 31));;;;这个范围的经纬
  14. lon1 = lat(ind(lon.lt.117.and.lon.gt.110))

  15. A=new(6,float)
  16. A=(/0,50,100,250,500,800/)

  17. sizes  = ispan(30,55,5)/5000.    ; 0.00025 to 0.00055
  18. colors = (/"orange","green","red","yellow","purple"/);,"blue","red","brown","red2","skyblue"/)
  19. labels  = (/"0~F25~~~50","50~F25~~~100","100~F25~~~250","250~F25~~~500","500~F25~~~800"/)
  20. xpos3    = (/  0.18,   0.33,  0.48,    0.63,  0.78/)
  21. xpos2    = (/  0.15,   0.30,  0.45,    0.60,  0.75/)
  22. markers1 = (/     16,      16,     16,       16,     16/)


  23.    wks  = gsn_open_wks("pdf","Scatter")
  24.     gsn_define_colormap(wks, "WhViBlGrYeOrRe")

  25. ; 填色
  26. ;************************************************
  27.    res              = True
  28.    res@gsnDraw      = False
  29.    res@gsnFrame     = False
  30.    res@tiMainString = "~F25~Obeserve Precipitation"
  31.    res@tiMainFontHeightF    = 0.022   ;set main title fontsize
  32.    
  33.    res@mpMinLatF = 31
  34.    res@mpMaxLatF = 37
  35.    res@mpMinLonF = 110
  36.    res@mpMaxLonF = 117
  37.    res@mpFillOn    = False
  38.    res@mpFillColor = False
  39.    res@tmXBTickSpacingF = 1   ;坐标轴标注间距
  40.    res@tmYLTickSpacingF = 1
  41.    res@tmXBLabelFontHeightF = 0.016
  42.    res@tmYLLabelFontHeightF = 0.016


  43.     res@mpOutlineOn                  = True  ; Use outlines from shapefile
  44.     res@mpOutlineBoundarySets        = "Geophysical"
  45.     res@mpNationalLineColor          = "black"
  46.     res@mpProvincialLineColor        = "black"
  47.     res@mpGeophysicalLineColor       = "black"
  48.     res@mpNationalLineThicknessF     = 2
  49.     res@mpProvincialLineThicknessF   = 2.5
  50.     res@mpGeophysicalLineThicknessF  = 2
  51.     res@mpOutlineSpecifiers          = (/"China","China:States"/)
  52.     res@mpDataBaseVersion            = "MediumRes"
  53.     res@mpDataSetName                = "Earth..4"
  54.         
  55.         ;;;;色标设置
  56.    ; res@lbLabelBarOn = True    ;显隐开关
  57.    ; res@lbLabelFontHeightF = 0.25
  58.    ; res@cnFillPalette="wh-bl-gr-ye-re"
  59.    ; res@cnLabelBarEndStyle   = "ExcludeOuterBoxes" ; 色标两端标注风格,ExcludeOuterBoxes是去掉色标两端色块,IcludeMinMaxLabels是色标两端显示最大最小值,默认是色标两端无标注
  60.    ; res@pmLabelBarWidthF     = 0.8      ;色标宽度
  61.    ; res@pmLabelBarHeightF        = 0.08   ; 色标高度
  62.    ; res@pmLabelBarOrthogonalPosF = 0.12  ;色标垂直偏移坐标,默认为0.02,正向上,负向下
  63.    ; res@cnFillOpacityF          = 0.5  ;不透明度,默认为1
  64.    res@pmTickMarkDisplayMode= "Always"
  65.     res@lgOrientation          = "horizontal"     ; Default is vertical
  66.   res@pmLegendWidthF         = 0.75             ; Make it wider
  67.   res@pmLegendOrthogonalPosF = -0.1             ; Move it up slightly
  68.   res@lgPerimOn              = False            ; Turn off the perimeter box


  69.    ;;色标名字设定
  70.    ; res@lbTitleOn            =  True
  71.    ; res@lbTitleString        =  "mm"
  72.    ; res@lbLabelFontHeightF   = 0.02;;;字体大小
  73.    ; res@lbTitlePosition      = "Bottom"
  74.            ; res@cnLevelSelectionMode =  "ExplicitLevels";等值线手动挡开始
  75.         ; res@cnLevels             =  (/0,50,100,250,500,800/)        

  76.    map = gsn_csm_map(wks,res)
  77.    
  78.    

  79.    dum_fill   = new(5,graphic)
  80.    mkres               = True
  81.    mkres@gsMarkerThicknessF = 2.0      ; Twice as thick
  82.    do i=0,4  ;;;6个区间
  83.        ii = ind(pre1.le.A(i+1).and.pre1.gt.A(i))
  84.        mkres@gsMarkerIndex = markers1(i)          ; Filled dots
  85.        mkres@gsMarkerSizeF = sizes(i)
  86.        mkres@gsMarkerColor = colors(i)

  87.            txres               = True
  88.            txres@txFontHeightF = 0.016             ;图例上文本的大小
  89.        txres@txJust        = "CenterLeft"      ;文本放在图例的那个位置

  90.            
  91.            ;;;;;其实没什么用,操作两小时,回到中华人民共和国成立前,只需要对地图哪儿设置就行了。。。。但是我还是要保留他
  92.            x=new(dimsizes(lon(ii)),float)
  93.            x=lon(ii)
  94.            y=new(dimsizes(lat(ii)),float)
  95.            y=lat(ii)
  96.            
  97.            dd=ind(lon(ii).gt.110.0 .and. lon(ii).lt.116.5)
  98.            bb=ind(lat(ii).lt.36.5 .and. lat(ii).gt.31.5)
  99.                         ;print(x(dd))
  100.                         ;print(in(lon(ii)))
  101.                         ; if(all(lat(ii).lt.37.and.lat(ii).gt.31))
  102.                 dum_fill(i)=gsn_add_polymarker(wks,map,x(dd),y(bb),mkres)
  103.                 gsn_polymarker_ndc(wks,           xpos2(i),0.15,mkres)
  104.                 gsn_text_ndc      (wks,labels(i),xpos3(i),0.15,txres)
  105.                
  106.                 delete(ii)
  107.                 delete(dd)
  108.                 delete(x)
  109.                 delete(bb)
  110.                 delete(y)
  111.    end do
  112.    

  113.    
  114.     draw(map)
  115.     frame(wks)   

复制代码



1736065156957.png

评分

参与人数 1金钱 +1 收起 理由
ahtoffff + 1 很给力!

查看全部评分

密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2025-1-6 09:19:06 | 显示全部楼层
楼主  请问,当文件中缺测值不止一个的时候该怎么设置呀
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2025-1-6 09:56:42 | 显示全部楼层
ahtoffff 发表于 2025-1-6 09:19
楼主  请问,当文件中缺测值不止一个的时候该怎么设置呀

把其他缺测值都换成一个缺测值即可
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2025-1-6 10:30:39 | 显示全部楼层
森下下士 发表于 2025-1-6 09:56
把其他缺测值都换成一个缺测值即可

太聪明了 点醒我了 我怎么没想到从原数据下手。。。。 感谢!!
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表