爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 1652|回复: 5

[其他] 求助,关于散点图绘制数据缺失的问题

[复制链接]

新浪微博达人勋

发表于 2018-5-6 16:13:06 | 显示全部楼层 |阅读模式

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

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

x
我用gsn_polymarker绘单个图正常显示,但用gsn_add_polymarker同时绘制三个plot时就缺失了很多点。
而且我用gsn_add_polymarker绘制简单数据时是正常的。

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

新浪微博达人勋

 楼主| 发表于 2018-5-6 16:21:30 | 显示全部楼层
本帖最后由 sc_j 于 2018-5-6 16:23 编辑

1.png
       2.png
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2018-5-7 17:33:56 | 显示全部楼层
代码如下


load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"

begin


  arr = (/800,900,1000,1100,1200,1300,1400,1500,1600,1700/)   
  colors = (/10,20,30,38,48,56,66,74,84,94,98/)  ; marker colors, dimsizes must
                                        ; be equal to dimsizes(arr)+1
  labels = new(dimsizes(arr)+1,string)  ; Labels for legend.
;---------------------------
loaddir             = "./"
   loadfilenm_obs      = "obs_9yrmean_prc_2005-2013.txt"
  loadfilenm_01      = "sta_1p5km_prc.txt"
  loadfilenm_09      = "sta_9km_prc.txt"
;;;;;;;;;;;;;;;;;;;;;;;obs  obs   obs  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  
f_obs = asciiread(loaddir+loadfilenm_obs,(/2301,13/),"float")
    printVarSummary(f_obs)
    obs = f_obs(:,3)
    lat = f_obs(:,2)
    lon = f_obs(:,1)

  npts = 2301                                    ; Number of points.
  ;lat  = random_uniform( 25., 50.,npts)         ; Create some dummy latitude
  ;lon  = random_uniform(235.,290.,npts)         ; and longitude data that
                                                ; will contain the position of
                                                ; our markers.

  R= f_obs(:,3)  ;  = random_uniform(-1.2,35.,npts)   ; This is dummy data for determining

  num_distinct_markers = dimsizes(arr)+1        ; number of distinct markers
  lat_new = new((/num_distinct_markers,dimsizes(R)/),float,-999)
  lon_new = new((/num_distinct_markers,dimsizes(R)/),float,-999)
;
; Group the points according to which range they fall in. At the
; same time, create the label that we will use later in the legend.
;      
  do i = 0, num_distinct_markers-1
    if (i.eq.0) then
      indexes = ind(R.lt.arr(0))
      labels(i) = "x < " + arr(0)
    end if
    if (i.eq.num_distinct_markers-1) then
      indexes = ind(R.ge.max(arr))
      labels(i) = "x >= " + max(arr)
    end if
    if (i.gt.0.and.i.lt.num_distinct_markers-1) then      
      indexes = ind(R.ge.arr(i-1).and.R.lt.arr(i))
      labels(i) = arr(i-1) + " <= x < " + arr(i)
    end if
;
; Now that we have the set of indexes whose values fall within
; the given range, take the corresponding lat/lon values and store
; them, so later we can color this set of markers with the appropriate
; color.
;
    if (.not.any(ismissing(indexes))) then
      npts_range = dimsizes(indexes)   ; # of points in this range.
      lat_new(i,0:npts_range-1) = lat(indexes)
      lon_new(i,0:npts_range-1) = lon(indexes)
    end if
    delete(indexes)            ; Necessary b/c "indexes" may be a different
                               ; size next time.
  end do
f_01 = asciiread(loaddir+loadfilenm_01,(/2301,4/),"float")
    ;printVarSummary(f_obs)
    obs01 = f_01(:,3)
    lat01 = f_01(:,2)
    lon01 = f_01(:,1)

  npts = 2301                                    ; Number of points.
  ;lat  = random_uniform( 25., 50.,npts)         ; Create some dummy latitude
  ;lon  = random_uniform(235.,290.,npts)         ; and longitude data that
                                                ; will contain the position of
                                                ; our markers.

  R01= f_01(:,3)  ;  = random_uniform(-1.2,35.,npts)   ; This is dummy data for determining
                                        ; how to color the markers.

  num_distinct_markers01 = dimsizes(arr)+1        ; number of distinct markers
  lat_new01 = new((/num_distinct_markers01,dimsizes(R01)/),float,-999)
  lon_new01 = new((/num_distinct_markers01,dimsizes(R01)/),float,-999)
;
; Group the points according to which range they fall in. At the
; same time, create the label that we will use later in the legend.
;      
  do i = 0, num_distinct_markers01-1
    if (i.eq.0) then
      indexes01 = ind(R01.lt.arr(0))
      labels(i) = "x < " + arr(0)
    end if
    if (i.eq.num_distinct_markers01-1) then
      indexes01 = ind(R01.ge.max(arr))
      labels(i) = "x >= " + max(arr)
    end if
    if (i.gt.0.and.i.lt.num_distinct_markers01-1) then      
      indexes01 = ind(R01.ge.arr(i-1).and.R01.lt.arr(i))
      labels(i) = arr(i-1) + " <= x < " + arr(i)
    end if

    if (.not.any(ismissing(indexes01))) then
      npts_range = dimsizes(indexes01)   ; # of points in this range.
      lat_new01(i,0:npts_range-1) = lat01(indexes01)
      lon_new01(i,0:npts_range-1) = lon01(indexes01)
    end if
    delete(indexes01)            ; Necessary b/c "indexes" may be a different
                               ; size next time.
  end do

  f_09 = asciiread(loaddir+loadfilenm_09,(/2301,4/),"float")
    obs09 = f_09(:,3)
    lat09 = f_09(:,2)
    lon09 = f_09(:,1)

  npts = 2301                                    ; Number of points.
  ;lat  = random_uniform( 25., 50.,npts)         ; Create some dummy latitude
  ;lon  = random_uniform(235.,290.,npts)         ; and longitude data that
                                                ; will contain the position of
                                                ; our markers.

  R09= f_09(:,3)  ;  = random_uniform(-1.2,35.,npts)   ; This is dummy data for determining
                                        ; how to color the markers.

  num_distinct_markers09 = dimsizes(arr)+1        ; number of distinct markers
  lat_new09 = new((/num_distinct_markers09,dimsizes(R09)/),float,-999)
  lon_new09 = new((/num_distinct_markers09,dimsizes(R09)/),float,-999)
;
; Group the points according to which range they fall in. At the
; same time, create the label that we will use later in the legend.
;      
  do i = 0, num_distinct_markers09-1
    if (i.eq.0) then
      indexes09 = ind(R09.lt.arr(0))
      labels(i) = "x < " + arr(0)
    end if
    if (i.eq.num_distinct_markers09-1) then
      indexes09 = ind(R09.ge.max(arr))
      labels(i) = "x >= " + max(arr)
    end if
    if (i.gt.0.and.i.lt.num_distinct_markers09-1) then      
      indexes09 = ind(R09.ge.arr(i-1).and.R09.lt.arr(i))
      labels(i) = arr(i-1) + " <= x < " + arr(i)
    end if
;
; Now that we have the set of indexes whose values fall within
; the given range, take the corresponding lat/lon values and store
; them, so later we can color this set of markers with the appropriate
; color.
;
    if (.not.any(ismissing(indexes09))) then
      npts_range = dimsizes(indexes09)   ; # of points in this range.
      lat_new09(i,0:npts_range-1) = lat09(indexes09)
      lon_new09(i,0:npts_range-1) = lon09(indexes09)
    end if
    delete(indexes09)            ; Necessary b/c "indexes" may be a different
                               ; size next time.
  end do


  wks = gsn_open_wks("ps",get_script_prefix_name())              ; send graphics to PNG file
  gsn_define_colormap(wks,"WhViBlGrYeOrRe")      ; define a different color map
  
  plot = new(3,graphic)
if(True)then
   mpres              = True
  mpres@gsnMaximize  = False             ; Maximize plot in frame.
  mpres@gsnFrame     = False            ; Don't advance the frame
  mpres@gsnDraw      = False
;
; Zoom in on United States.
;
   mpres@mpMinLatF   = 29.2
   mpres@mpMaxLatF   = 32.8
   mpres@mpMinLonF   = 119.2
   mpres@mpMaxLonF   = 123.
   

   mpres@mpDataSetName       = "Earth..4"
   mpres@mpDataBaseVersion   = "MediumRes"
   mpres@mpOutlineOn         = True
   mpres@mpOutlineSpecifiers = (/"China:states","Taiwan"/)
   mpres@mpGeophysicalLineThicknessF = 1.5

   mpres@mpFillOn              = True
   mpres@mpFillDrawOrder       = "PostDraw"
   mpres@mpFillAreaSpecifiers  = (/"Water","Land"/)
   mpres@mpSpecifiedFillColors = (/"White","transparent"/)

   mpres@gsnLeftStringFontHeightF = 0.023
   mpres@tmXBLabelFontHeightF     = 0.017
   mpres@tmYLLabelFontHeightF     = 0.017
   mpres@mpOutlineBoundarySets       = "NoBoundaries"   
   mpres@pmTickMarkDisplayMode       = "Always"   

   mpres@gsnPanelLabelBar=True
   
   ;mpres@cnLevels= (/800,900,1000,1100,1200,1300,1400,1500,1600,1700/)
   ;mpres@cnFillColors=(/10,20,30,38,48,56,66,74,84,94,98/)
  mpres@mpFillColors = (/"transparent","transparent", \
  "lightgray","transparent"/)    ;assign light gray to land masses
end if
  mpres@tiMainString = "(a)obs"
  plot(0) = gsn_csm_map(wks,mpres)
  mpres01=mpres
  mpres01@tiMainString ="(b)1p5km"
  plot(1)= gsn_csm_map(wks,mpres01)
  mpres09=mpres
  mpres09@tiMainString ="(c)9km"
  plot(2)= gsn_csm_map(wks,mpres09)

  lbres = True
  lbres@lbPerimOn            = False               ; no label bar box
  lbres@lbOrientation        = "Horizontal"        ; orientation
  lbres@vpWidthF             = 0.7                 ; size
  lbres@vpHeightF            = 0.1
  lbres@lbLabelFontHeightF   = 0.012               ; label font height
  lbres@lbLabelAlignment     = "InteriorEdges"     ; where to label
  lbres@lbMonoFillPattern    = True                ; fill sold
  lbres@lbFillColors         = colors;(/10,20,30,38,48,56,66,74,84,94,98/)      ; must be RGB triplets
  gsn_labelbar_ndc(wks, 11, arr, 0.15, 0.35, lbres)

  gsres               = True
  gsres@gsMarkerIndex = 16          ; Use filled dots for markers.

do i = 0, num_distinct_markers-1
    if (.not.ismissing(lat_new(i,0)))
      gsres@gsMarkerColor      = colors(i)
      ;gsn_polymarker(wks,plot(0),lon_new(i,:),lat_new(i,:),gsres)
      p0=gsn_add_polymarker(wks,plot(0),lon_new(i,:),lat_new(i,:),gsres)
      ;print(lon_new(i,:))
      ;draw(p0)

      end if
      
  end do

do i = 0, num_distinct_markers01-1
   if (.not.ismissing(lat_new01(i,0)))
      gsres@gsMarkerColor      = colors(i)
      ;gsn_polymarker(wks,plot(1),lon_new01(i,:),lat_new01(i,:),gsres)
      p1=gsn_add_polymarker(wks,plot(1),lon_new01(i,:),lat_new01(i,:),gsres)
      ;draw(p1)
      end if
end do

do i = 0, num_distinct_markers09-1
   if (.not.ismissing(lat_new09(i,0)))
      gsres@gsMarkerColor      = colors(i)
      ;gsn_polymarker(wks,plot(2),lon_new09(i,:),lat_new09(i,:),gsres)
      p2=gsn_add_polymarker(wks,plot(2),lon_new09(i,:),lat_new09(i,:),gsres)
      ;draw(p2)
      end if
end do


        panelres             = True
        panelres@gsnMaximize = True

        gsn_panel(wks,plot,(/1,3/),panelres)

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

新浪微博达人勋

发表于 2018-5-13 09:16:42 | 显示全部楼层
感谢分享!!!!!!
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

发表于 2019-6-18 10:40:49 | 显示全部楼层
您好,请问解决了吗
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2019-6-18 10:57:08 | 显示全部楼层
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

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