[ncl-talk] Looking to create a scatterplot of x vs y colored based on value of z
Tyler Herrington
therring at uwaterloo.ca
Wed Jun 6 16:11:56 MDT 2018
Good Afternoon,
I am looking to create a scatterplot of Change in Tree Fraction vs Change
in Grass Fraction where the scatterplot values are colored based on their
change in albedo value.
Each of Tree, Grass and Albedo have been converted into 1D arrays with 6480
values
Albedo values vary between -0.415 and +0.153, and I am looking to create a
colormap with 19 colors from the GMT_polar colormap.
My script works ok for cases where z = ind() returns a single value (which
is the case when i = 0), however it fails if z returns 2 or more values
(for example when i=1), and thus I was hoping to put this out to see if
anyone had any suggestions on how to fix this problem?
begin
;********************************************
; Read in Tundra and Boreal Albedo Feedbacks
;********************************************
dirA = "/praid/users/herringtont/Caldwell_2016/GFDL_Albedo/albedo/"
dirV = "/praid/users/herringtont/Caldwell_2016/Vegetation_Data/"
A1 =
dirA+"albedo_Amon_GFDL-ESM2G_rcp45_r1i1p1_208001-209912_avg_diff_LandOnly_NH.nc"
T1 = dirV+"treeFrac_Lmon_GFDL-ESM2G_rcp45_r1i1p1_diff_Frac_LandOnly_NH.nc"
G1 = dirV+"grassFrac_Lmon_GFDL-ESM2G_rcp45_r1i1p1_diff_Frac_LandOnly_NH.nc"
A2 = addfile(A1,"r")
T2 = addfile(T1,"r")
G2 = addfile(G1,"r")
ALB = A2 ->rsuscs(4,:,:)
Grass = G2 ->grassFrac(4,:,:)
Tree = T2 ->treeFrac(4,:,:)
;********************************************
; Reshape ALB, Tree, and Grass from 2D to 1D
;********************************************
ALB1d = ndtooned(ALB)
Tree1d = ndtooned(Tree)
Grass1d = ndtooned(Grass)
;************************************
; Create Color Scale for Scatterplot
;************************************
dALB = dimsizes(ALB1d)
colorALB = new(dALB,"integer")
clrs = (/2,3,4,5,6,7,8,9,10,12,13,14/)
i = 0
do while (i.le.10)
j = i-1
if (i.eq.0) then
VAL1 = -0.45
VAL2 = -0.40
else
VAL1 = -0.35+(0.05*j)
VAL2 = -0.30+(0.05*j)
end if
print(VAL1)
print(VAL2)
z = ind(ALB1d.gt.VAL1.and.ALB1d.lt.VAL2)
print(z)
print(i)
colorALB(z) = clrs(i)
i = i+1
end do
print(colorALB)
;******************************************************
; Create April Mean Veg vs Alb Change Scatterplot
;******************************************************
wks = gsn_open_wks("png","GFDL_Veg_Alb_Apr_Scatter_Color")
gsn_define_colormap(wks,"GMT_polar")
res = True
res at gsnDraw = False ; Don't draw plot or advance
res at gsnFrame = False ; frame. Will do this later.
res at tiXAxisString = "Change in Tree Fraction"
res at tiYAxisString = "Change in Grass Fraction"
square = NhlNewMarker(wks, "y", 35, 0.0, 0.0, 1., 0.5, 0.)
res at xyMarkLineMode = "Markers"
res at xyMarkerThicknessF = 2.5
res at xyMarkerColor = colorALB
res at xyMarker = square ; this is a filled square
plot = gsn_csm_xy(wks,Tree1d,Grass1d,res)
maximize_output(wks,False)
system("mv *.png /home/herringtont/Caldwell_2016/figures/scatterplot")
end
here is the printout from the script when I execute it currently:
Variable: VAL1
Type: float
Total Size: 4 bytes
1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) -0.45
Variable: VAL2
Type: float
Total Size: 4 bytes
1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) -0.4
Variable: z
Type: integer
Total Size: 4 bytes
1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) 3265
Variable: i
Type: integer
Total Size: 4 bytes
1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) 0
Variable: VAL1
Type: float
Total Size: 4 bytes
1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) -0.35
Variable: VAL2
Type: float
Total Size: 4 bytes
1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) -0.3
fatal:Number of dimensions on right hand side do not match number of
dimension in left hand side
fatal:["Execute.c":8640]:Execute: Error occurred at or near line 61 in file
Albedo_Veg_GFDL_Scatter.ncl
Thank you for your help,
Sincerely,
Tyler Herrington, MSc
PhD Student (Climate Science)
Geography and Environmental Management
University of Waterloo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180606/fe4c1b6b/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: albedo_Amon_GFDL-ESM2G_rcp45_r1i1p1_208001-209912_avg_diff_LandOnly_NH.nc
Type: application/octet-stream
Size: 321596 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180606/fe4c1b6b/attachment-0003.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: treeFrac_Lmon_GFDL-ESM2G_rcp45_r1i1p1_diff_Frac_LandOnly_NH.nc
Type: application/octet-stream
Size: 320884 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180606/fe4c1b6b/attachment-0004.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: grassFrac_Lmon_GFDL-ESM2G_rcp45_r1i1p1_diff_Frac_LandOnly_NH.nc
Type: application/octet-stream
Size: 320864 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180606/fe4c1b6b/attachment-0005.obj>
More information about the ncl-talk
mailing list