Re: Scatter plot markers

From: Mateus Teixeira <mateus.teixeira_at_nyahnyahspammersnyahnyah>
Date: Wed, 7 Oct 2009 14:44:03 -0300

Hi Mary,

As you've said, a XY plot requires at least two points per curve, so this
example will fail in a case you have a mark assigned to a single point. So,
it still necessary the use of gsn_add_polymarker in these cases. Below is
the previous script applying both functions:

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

begin
  x = ispan(1,10,1)
  y = x*log(x*1.)/cos(x*1.)
  marks = (/1,1,1,1,2,3,3,3,1,1/)

  scatterRes = True
  scatterRes_at_xyMarkLineMode = "Markers"
  scatterRes_at_xyMarkerSizeF = 0.03
  scatterRes_at_gsnDraw = False ; <= disabling drawing, only at the
end of script
  scatterRes_at_gsnFrame = False
  scatterRes_at_trYMinF = min(y)-10
  scatterRes_at_trYMaxF = max(y)+10
  scatterRes_at_trXMinF = min(x)-10
  scatterRes_at_trXMaxF = max(x)+10

  wks = gsn_open_wks("x11","test")

  ; graphical arrays to hold the XY plots and solitary markers
  marksAlone = new( max(marks), graphic )
  plots = new( max(marks), graphic )

  marker_types = 3 ; We have marker types 1, 2, and 3
  alone = 0 ; counter for solitary
markers
  do mtype = 0,marker_types-1
    ii = ind(marks.eq.mtype+1)
    xtmp = x(ii)
    ytmp = y(ii)
    scatterRes_at_xyMarker = mtype+1

    ; verifying if there is only one pair of data for a specific mark
    if ( dimsizes(ii).gt.1 ) then
       plots(mtype) = gsn_csm_xy( wks, xtmp, ytmp, scatterRes )
    else
       marksAlone(alone) = gsn_add_polymarker( wks, plots(mtype-1), x(ii),
y(ii), scatterRes )
       alone=alone+1
    end if

    delete(ii)
    delete(xtmp)
    delete(ytmp)

  end do

  draw(plots) ; <= plotting all together
  frame(wks)

end

Best regards,

Mateus

2009/10/7 Mary Haley <haley_at_ucar.edu>

> Hi Mateus,
> Glad you figured it out.
>
> For the other users that may be wondering about this: the "xyMarkers"
> resource doesn't apply to every point in a single curve,
> but rather every set of curves in a multi-curve plot.
>
> I was going to recommend that you treat each point as its own curve, but
> the XY plot object requires at least two points per curve, so
> that wouldn't have worked either.
>
> Here's one kludgy method, if you want to avoid using gsn_add_marker:
>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>
> begin
> x = ispan(1,10,1)
> y = x*log(x*1.)/cos(x*1.)
> marks = (/1,1,1,1,2,3,3,3,2,1/)
>
> scatterRes = True
> scatterRes_at_xyMarkLineMode = "Markers"
> scatterRes_at_xyMarkerSizeF = 0.03
> scatterRes_at_gsnFrame = False
> scatterRes_at_trYMinF = min(y)
> scatterRes_at_trYMaxF = max(y)
> scatterRes_at_trXMinF = min(x)
> scatterRes_at_trXMaxF = max(x)
>
> wks = gsn_open_wks("x11","test")
>
> marker_types = 3 ; We have marker types 1, 2, and 3
> do mtype = 1,marker_types-1
> ii = ind(marks.eq.mtype)
> xtmp = x(ii)
> ytmp = y(ii)
> scatterRes_at_xyMarker = mtype
>
> plot = gsn_csm_xy( wks, xtmp, ytmp, scatterRes )
>
> delete(ii)
> delete(xtmp)
> delete(ytmp)
> end do
>
> frame(wks)
>
> end
>
>
> --Mary
>
> On Oct 6, 2009, at 8:50 PM, Mateus Teixeira wrote:
>
> Dear NCL users,
>
> I'm sorry for the last message (copied below). After trying in a wrong way,
> I realize that I only can do what I want with gsn_add_polymarker function.
>
> Best regards and apologize for that message.
>
> Mateus
>
>
> ---------- Forwarded message ----------
> From: Mateus Teixeira <mateus.teixeira_at_gmail.com>
> Date: 2009/10/6
> Subject: Scatter plot markers
> To: ncl-talk_at_ucar.edu
>
>
> Dear NCL users,
>
> I'm trying to create a scatter plot in which the points have differente
> marks, according to an array that gives the mark indexes, but it seems that
> the xyMarkers are not getting the array with the marks. Please see the
> script below:
>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>
> begin
>
> x = ispan(1,10,1)
> y = x*log(x*1.)/cos(x*1.)
> marks = (/1,1,1,1,2,3,3,3,2,1/)
>
>
> scatterRes = True
> scatterRes_at_xyMarkLineModes = "Markers"
> scatterRes_at_xyMarkers = marks
> scatterRes_at_xyMarkerSizeF = 0.03
>
> wks = gsn_open_wks("ps","test")
> plot = gsn_csm_xy( wks, x, y,
> scatterRes )
>
> end
>
> Can you see what I'm doing wrong?
>
> Best regards,
>
> --
> Mateus da Silva Teixeira
> Meteorologista
> Instituto de Pesquisas Meteorológicas - IPMet
> Universidade Estadual Paulista - UNESP
> Av. Luis Edmundo Carrijo Coube, 14-01 - Cx. Postal 281 - CEP 17033-360
> Bauru - SP - Brasil
> Fone: +55 14 3103-6030 / fax: 3203-3649
>
> Registered Linux User #466740 (http://counter.li.org/)
>
>
>
> --
> Mateus da Silva Teixeira
> Meteorologista
> Instituto de Pesquisas Meteorológicas - IPMet
> Universidade Estadual Paulista - UNESP
> Av. Luis Edmundo Carrijo Coube, 14-01 - Cx. Postal 281 - CEP 17033-360
> Bauru - SP - Brasil
> Fone: +55 14 3103-6030 / fax: 3203-3649
>
> Registered Linux User #466740 (http://counter.li.org/)
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>

-- 
Mateus da Silva Teixeira
Meteorologista
Instituto de Pesquisas Meteorológicas - IPMet
Universidade Estadual Paulista - UNESP
Av. Luis Edmundo Carrijo Coube, 14-01 - Cx. Postal 281 - CEP 17033-360
Bauru - SP - Brasil
Fone: +55 14 3103-6030 / fax: 3203-3649
Registered Linux User #466740 (http://counter.li.org/)
Received on Wed Oct 07 2009 - 11:44:03 MDT

This archive was generated by hypermail 2.2.0 : Fri Oct 09 2009 - 08:29:22 MDT