[ncl-talk] xy-plot marker color + style
Kreienkamp Frank
Frank.Kreienkamp at dwd.de
Sun Nov 26 22:15:28 MST 2017
Hello,
what i have found is an answer from Mary Haley back in the year 2010:
https://www.ncl.ucar.edu/Support/talk_archives/2010/0956.html
' ... The xyMarkerColors resource only works if you have multiple curves.
It's not a way to take points in a single curve and color them
differently. ...'
Taking this into account and adding some suggestions from Denis Shea the source code looks like:
; ***********************************************
; xy_4.ncl
;
; Concepts illustrated:
; - Drawing a scatter plot
; - Changing the markers in an XY plot
; - Changing the marker color in an XY plot
; - Changing the marker size in an XY plot
; - Creating your own markers for an XY plot
;
; ***********************************************
;
; These files are loaded by default in NCL V6.2.0 and newer
; load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
; load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
;************************************************
; MAIN
;************************************************
begin
nln = 2
nmk = 5
data = new((/nln,nmk/),float, -999.0)
data(:,0) = (/ 4.80, -4.26 /)
data(:,1) = (/ 4.97, 14.63 /)
data(:,2) = (/ 4.55, -22.12 /)
data(:,3) = (/ 4.47, -4.51 /)
data(:,4) = (/ 3.11, 19.09 /)
colors = (/"white","black","blue","green" ,"cyan", "darkorange","chocolate4" /)
Marker = (/16,14,11,7,3 /)
x = new((/nmk,3/),float)
y = new((/nmk,3/),float)
do j = 0 , nmk - 1
x(j,:) = data (0,j)
y(j,:) = data (1,j)
end do
print(colors(2:)+" "+Marker)
;************************************************
; plotting parameters
;************************************************
wks = gsn_open_wks ("x11","xy-test") ; send graphics to PNG file
gsn_define_colormap(wks,colors)
res = True ; plot mods desired
res at tiMainString = "Scatter Plot" ; add title
res at xyMarkLineModes = "Markers" ; choose which have markers
res at xyMarkers = Marker ; choose type of marker
res at xyMarkerColors = colors(2:) ; Marker color
res at xyMarkerSizeF = 0.01 ; Marker size (default 0.01)
;res at tmLabelAutoStride = True ; nice tick mark labels
plot = gsn_csm_xy (wks,x,y,res) ; create plot
end
Unfortunately only one dot is plotted. So still I do something wrong.
Could you please help.
Frank
Von: ncl-talk [mailto:ncl-talk-bounces at ucar.edu] Im Auftrag von Kreienkamp Frank
Gesendet: Donnerstag, 23. November 2017 15:19
An: ncl-talk at ucar.edu<mailto:ncl-talk at ucar.edu>
Betreff: [ncl-talk] xy-plot marker color + style
Hallo,
i am trying to plot a xy-plot. With each marker having a different color and marker style:
; ***********************************************
; xy_4.ncl
;
; Concepts illustrated:
; - Drawing a scatter plot
; - Changing the markers in an XY plot
; - Changing the marker color in an XY plot
; - Changing the marker size in an XY plot
; - Creating your own markers for an XY plot
;
; ***********************************************
;
; These files are loaded by default in NCL V6.2.0 and newer
; load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
; load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
;************************************************
begin
;************************************************
data = new((/2,5/),float)
data at _FillValue = -999.
data(:,0) = (/ 4.80, -4.26 /)
data(:,1) = (/ 4.97, 14.63 /)
data(:,2) = (/ 4.55, -22.12 /)
data(:,3) = (/ 4.47, -4.51 /)
data(:,4) = (/ 3.11, 19.09 /)
colors = (/"white","black","blue","green" ,"cyan", "darkorange","chocolate4" /)
Marker = new(5,integer)
Marker = (/16,14,11,7,3 /)
print(colors)
print(Marker)
;************************************************
; plotting parameters
;************************************************
wks = gsn_open_wks ("png","xy-test") ; send graphics to PNG file
gsn_define_colormap(wks,colors)
res = True ; plot mods desired
res at tiMainString = "Scatter Plot" ; add title
res at xyMarkLineModes = "Markers" ; choose which have markers
res at xyMarkers = Marker ; choose type of marker
res at xyMarkerColors = colors (2:) ; Marker color
res at xyMarkerSizeF = 0.01 ; Marker size (default 0.01)
res at tmLabelAutoStride = True ; nice tick mark labels
plot = gsn_csm_xy (wks,data(0,:),data(1,:),res) ; create plot
end
Unfortunately all markers have the same color and style. What am i doing wrong?
Thanks in advance
Frank
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171127/a20f95a5/attachment.html>
More information about the ncl-talk
mailing list