Color Maps
Charts using color to depict values or false color maps.
colormap.gle
colormap.gle
! Example of a color map with a scale.
! Author: Francois Tonneau
! These are the number of steps we will require for a color gradient. Higher
! numbers result in a smoother gradient at the expense of processing time.
! Decrease x_steps and y_steps if the figure takes too long to appear.
x_steps = 250
y_steps = 250
size 13 10
set font ss
amove 2 2
begin graph
size 6 6
fullsize
title "Landscape" hei 0.4 dist 0.5
xaxis min -2 max 2
yaxis min -2 max 2
ticks off
labels dist 0.25
xtitle "X" hei 0.4 dist 0.5
ytitle "Y" hei 0.4 dist 0.5
! When called from within a graph block, the 'colormap' command assumes a
! different, simpler syntax. The first argument is a subroutine that assigns
! a numeric value in the 0-1 range to (x, y) graph coordinates. The second
! and third arguments are the number of steps for x and y, respectively.
! The last argument (the one after the 'palette' keyword) is a custom
! color palette. *The first and last arguments should be non-quoted.*
colormap z(x,y) x_steps y_steps palette glow
end graph
! Here is the subroutine we use to assign numeric values to (x, y) graph
! coordinates:
sub z x y
local sigma = 0.75
local value = exp(-(x^2 + y^2)/(2 * sigma^2))
return value
end sub
! Our palette subroutine returns a nonlinear mixture (in standard RGB space) of
! three colors as a function of numeric input:
sub glow z
local r_cool = 0; local g_cool = 78; local b_cool = 88
local r_luke = 205; local g_luke = 205; local b_luke = 205
local r_warm = 205; local g_warm = 92; local b_warm = 92
if z < 0.50 then
local w = sqrt(z/0.50)
local r = w * r_luke + (1 - w) * r_cool
local g = w * g_luke + (1 - w) * g_cool
local b = w * b_luke + (1 - w) * b_cool
end if
if z >= 0.50 then
local w = sqrt((z - 0.50)/0.50)
local r = w * r_warm + (1 - w) * r_luke
local g = w * g_warm + (1 - w) * g_luke
local b = w * b_warm + (1 - w) * b_luke
end if
return rgb255(r, g, b)
end sub
set hei 0.28 just bl
! We add a custom color scale:
height = 2.0
width = 0.6
for z = 0 to 0.9 step 0.1
amove 9.5 height
box width width fill glow(z)
rmove 0.8 -0.1
write format$(z, "fix 2")
height = height + width
next z
rmove 0 width
write "1.00"
set hei 0.4 just cc
amove 11.5 5
write "Z"
! This script ends our tutorial. Although we have covered a lot of ground, feel
! free to consult the User Manual for the full details on these topics, as well
! as information on other GLE options and commands.
colormapcontour.gle
colormapcontour.gle colormapcontour.zip zip file contains all files for this figure.
colormapcontour.gle
! Example of how to use color map and contour at the same time.
! Plot of modelling results coming from Abaqus.
! By Fabien Leonard.
size 12 12
set font texcmr
include "color.gle"
include "contour.gle"
! creates the z-value file to be used by the contour command
begin fitz
data "Zstress.csv"
x from 0 to 2 step 0.1
y from 0 to 2 step 0.1
ncontour 6
end fitz
begin contour
data "Zstress.z"
values from 100 to 800 step 100
end contour
begin graph
title "Modelling results of specimen stress (in MPa)"
xtitle "Bolt shortening (mm)"
ytitle "Step"
xticks color white
yticks color white
colormap "Zstress.z" 500 500 color
data "Zstress-cdata.dat"
d1 line color white lwidth 0.02
end graph
amove xg(xgmax)+0.5 yg(ygmin)
color_range_vertical zmin 0 zmax 815 zstep 50 pixels 1500 format "fix 0"
contour_labels file "Zstress-clabels.dat" format "fix 0"
heatmap.gle
heatmap.gle heatmap.zip zip file contains all files for this figure.
heatmap.gle
! Example of heatmap with black/white numeric labels.
! Author: Francois Tonneau
size 22 14
set font ss hei 0.3
include palettes.gle
! Draw the frame around the map via a graph block.
amove 3 2
begin graph
size 14 10
fullsize
xaxis min 0 max 12 ftick 0.5 dticks 1
yaxis min 0 max 12 ftick 0.5 dticks 1
xtitle Year adist 0.9
ytitle Month adist 1.2
side off
ticks off
xlabels off
x2labels off
ylabels off
y2labels off
labels hei 0.4
data "heatmap.dat"
xnames 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960
ynames Dec Nov Oct Sep Aug Jul Jun May Apr Mar Feb Jan
end graph
! Draw the map.
low = 100
high = 630
dx = xg(2) - xg(1)
dy = yg(2) - yg(1)
sub adjusted z
return (z - low) / (high - low)
end sub
for col = 1 to ndatasets()
n = ndata(d[col])
for row = 1 to n
z = datayvalue(d[col], row)
amove xg(col - 1) yg(n - row)
set color white lwidth 0.01
box dx dy just bl fill magma(adjusted(z))
rmove 0.33 0.32
set color magma_text(adjusted(z))
write z
next row
next col
! Add a custom color ramp on the right.
low = 70 ! => stretch the ramp down for prettier looks
high = 630
dy = 0.015
amove 19 2.8
for z = low to high
set color magma(adjusted(z)) lwidth 0
box 0.8 dy just bl fill magma(adjusted(z))
rmove 0 dy
next z
set color gray50 lwidth 0.03 just lc
amove 20 2.8+(30*dy)
for tick = 100 to 600 step 100
write tick
rmove 0 1.5
next tick
informationgain.gle
informationgain.gle
size 10 8
include "color.gle"
set font texcmr
tpos = 50; tneg = 50
tot = tpos + tneg
sub entropy p
if (p = 0) or (p = 1) then return 0
else return -p*log(p)/log(2) - (1-p)*log(1-p)/log(2)
end sub
sub information_gain lpos lneg
local rpos = tpos - lpos
local rneg = tneg - lneg
local ltot = lpos + lneg
local rtot = rpos + rneg
return entropy(tpos/tot) - &
ltot/tot*entropy(sdiv(lpos,ltot)) - rtot/tot*entropy(sdiv(rpos,rtot))
end sub
begin graph
xaxis min 0 max tpos
yaxis min 0 max tneg
title "Information Gain"
xtitle "# positives in left branch"
ytitle "# negatives in left branch"
colormap information_gain(x,y) 250 250 color
end graph
set hei 0.29
amove xg(xgmax)+0.3 yg(ygmin)
color_range_vertical zmin 0 zmax 1 zstep 0.1 pixels 500 format "fix 1"
maungazoom.gle
maungazoom.gle maungazoom.zip zip file contains all files for this figure.
maungazoom.gle
size 16 8
include "color.gle"
! draw left graph
amove 0 0
begin graph
size 8 8
title "Auckland's Maunga Whau Volcano"
colormap "volcano.z" 100 100 palette palette_blue_white_red
end graph
! define zoom rectangle on left graph
zx0 = 1; zy0 = 4
zx1 = 8; zy1 = 12
! draw zoom rectangle in yellow
gsave
set color yellow lwidth 0.1
amove xg(zx0) yg(zy0)
box xg(zx1)-xg(zx0) yg(zy1)-yg(zy0)
grestore
! draw right graph
amove 7 0
begin graph
size 8 8
title "Zoom on ("+num$(zx0)+","+num$(zy0)+") x ("+num$(zx1)+","+num$(zy1)+")"
xaxis min zx0 max zx1
yaxis min zy0 max zy1
colormap "volcano.z" 100 100 palette palette_blue_white_red
end graph
! draw vertical color range
amove 14.5 yg(ygmin)
color_range_vertical zmin 0 zmax 180 zstep 20 palette palette_blue_white_red
polenja.gle
polenja.gle polenja.zip zip file contains all files for this figure.
polenja.gle
size 18 19
include "color.gle"
set lwidth .02 hei .7 font texcmr
imax = 0; imaxc = 0
dpsi = 2.5; dphi = 2.5
! dpsi = stepwidth in psi direction, i.e. angle of latitude or elevation;
! dphi = stepwidth in phi direction, i.e. angle of longitude or azimuth.
file$ = "serguei2.nja"
! open result file with three rows: psi phi intensity
! first open to find overall maximum intensity = imax
! and maximum intensity at center = imaxc (i.e. for psi=0)
fopen file$ inchan read
until feof(inchan)
fread inchan psi phi i
if i>imax then
imax = i
end if
if psi=0 then
if i>imaxc then
imaxc = i
end if
end if
next
fclose inchan
! now open result file for actual plotting
! colors are defined with rgb color scheme:
! rgb(0,0,1) (i.e. blue) corresponds to i=0
! rgb(1,0,0) (i.e. red) corresponds to i=max
fopen file$ inchan read
until feof(inchan)
fread inchan psi phi i
amove 8.2 8.2
if psi=0 then
circle dphi fill cvtrgb(imaxc/imax,0,1-imaxc/imax)
else
begin path fill cvtrgb(i/imax,0,1-i/imax)
arc 8*sin(torad(psi+dpsi/2))/(1+cos(torad(psi+dpsi/2))) phi-dphi/2 phi+dphi/2
narc 8*sin(torad(psi-dpsi/2))/(1+cos(torad(psi-dpsi/2))) phi+dphi/2 phi-dphi/2
end path
end if
next
fclose inchan
! labeling
circle 8
for c = 0 to 3
begin rotate c*90
rmove 8 0
rline 0.2 0
end rotate
next c
rmove 8.2 0
set just lc
write "\varphi =0\movexy{-.15}{0}\char{23}"
rmove -8.2 8.2
set just bc
write "\varphi =90\movexy{-.15}{0}\char{23}"
amove 8.2-5 17.5
begin name range
colormap "x" 0 1 0 1 100 1 10 1 palette palette_blue_purple_red
end name
amove pointx(range.lc)-0.1 pointy(range.lc)
set just rc
write "I = 0"
amove pointx(range.rc)+0.1 pointy(range.rc)
set just lc
write "I = max."
ramps.gle
ramps.gle
! Example with color ramps.
! Author: Francois Tonneau
size 19 19
set font ss hei 0.6
include palettes.gle
sub paintslice hue
set color hue lwidth 0
box 0.02 0.8 just bl fill hue
rmove 0.02 0
end sub
amove 2 17
set color black
write "inferno"
rmove 0 -1
for z = 0 to 750
paintslice inferno(z/750)
next z
amove 2 15
set color black
write "magma"
rmove 0 -1
for z = 0 to 750
paintslice magma(z/750)
next z
amove 2 13
set color black
write "plasma"
rmove 0 -1
for z = 0 to 750
paintslice plasma(z/750)
next z
amove 2 11
set color black
write "viridis"
rmove 0 -1
for z = 0 to 750
paintslice viridis(z/750)
next z
amove 2 9
set color black
write "cividis"
rmove 0 -1
for z = 0 to 750
paintslice cividis(z/750)
next z
amove 2 7
set color black
write "davos"
rmove 0 -1
for z = 0 to 750
paintslice davos(z/750)
next z
amove 2 5
set color black
write "devon"
rmove 0 -1
for z = 0 to 750
paintslice devon(z/750)
next z
amove 2 3
set color black
write "oslo"
rmove 0 -1
for z = 0 to 750
paintslice oslo(z/750)
next z