Cyclic data with color

In the graph of Mississippi river annual discharge is it possible to plot each line with a different color (following the legend)? How?

)

I assume -C*cpt* would read a third column (-Z) ?

Yes, it does. But the data file does not have that info. There are two columns plot with the -wa option:

gmt plot $Data -W0.25p,red -wa -R0/12/$min/$max -JX20c/13c -Y8c -Bxa1g1+lmonth -Byafg -BWSne

Daily discharge rate in m^/s for the Mississippi River, 1930-1940.

1930-01-01T 14527
1930-01-02T 14810
1930-01-03T 15065
1930-01-04T 15178
1930-01-05T 15234
1930-01-06T 15178
1930-01-07T 15178
1930-01-08T 15234
1930-01-09T 15291
1930-01-10T 15461
1930-01-11T 15631
1930-01-12T 15801
1930-01-13T 16169
1930-01-14T 17103

Can you do something like :

gmt math -fiT -o1 -T1930-01-01T/1930-01-14T/1 --TIME_UNIT=d --TIME_EPOCH=1930-01-01 T = vector.txt
paste -d "," filedata.txt vector.txt > newfiledata.txt

(first line create a vector from 0 to N : 1 count per day from 1930-01-01 to 1930-01-14)
(second line concatenates horizontally the vector file as a third column of the datafile … assuming no header)
?

1 Like

I didn’t try it yet. But I make some progress using autocolor but I had to manually split the data file in segment for year (i.e. add a > at the end of each year).

gmt plot $Data -W0.25p,auto -wa

Now, I am searching how automatically split the file.

I usually use awk in loops …

Something like (need to be adjusted/tested)

for year in 1930..1935; 
do
awk -v var=$year -F[-] '{ if ($1 == var)  print $0 }' > $year.txt
done

?

1 Like

BTW, not sure but I don’t think it works because I want to plot lines and (as far as I know) the z-value must be in the header (not in the 3rd column). But it could work for symbols.

I think this would work as long as you do not mind constructing the legend manually (with 6.2.0rc1):

gmt begin GMT_cycle_2
gmt plot @mississippi.txt -R0/1/0/50 -JX15c/7c -W2p,auto -Bxaf -Byaf+l"10@+3@+ m@+3@+/s" -BWSrt+t"Mississippi river annual discharge" -i0,1+s1e-3 -wy -g0z0.05+n --COLOR_SET=royalblue1,deepskyblue1,lightskyblue1,cadetblue1,aquamarine1,springgreen1,darkolivegreen1,yellow1,rosybrown1,wheat1,brown1
gmt end show

A ridiculous idea could be to do it with batch module …

Agree with @meghanj that you will need to do a manual legend if you want specific language for each colored line. If you add -l you do get one entry per line but they would all say the same thing (whatever label you select).

Thanks. It works.

I must say that I don’t understand why does -g0z0.05+n works.

It means if the data (z) in column 0 changes by more than 0.05 then we have gotten to the end of one of the 0-1 x-values and we should add a gap in the plotting. Yes, a bit cryptic. @meghanj will remember I thought we should add some examples with illustrations for -g since it is very powerful but oh so dangerous in the hands of the uninitiated.

Thanks @pwessel. And in this case, why 0.05 works to split the time data by year?

Must admit I cannot quite recall but remember after -w your x-values are all in the 0-1 range and they repeat, so when the values goes 0.92, 0.95, 0.98, 0.02, 0.07, … then there is a step backwards in next minus previous I think. Perhaps 0.05 was picked since it is the point spacing (?).

1 Like

The +n is key for 0.05 to work, since it places segment headers based on the previous value minus the current value (i.e., when there is a sufficient jump from a larger number to a smaller number). It works here because the data are sequential. I have to admit that I chose 0.05 relatively arbitrarily while looking at the data.

I’ll open an issue for tracking the expansion of the cookbook info for -g.

1 Like

I managed to get this figure.

In the legend, I plot circles but I would like to plot line. Is it possible to select it color from the cpt? I try this but it didn’t work S 0.1i - 0.15i - 4p,z=1930 0.3i 1930.
@meghanj is that what you meant when you said I would have to do the legend manually?

Full script

gmt begin GMT_cycle_2 png
	gmt set GMT_THEME cookbook
	gmt makecpt -Ccategorical -T1930/1940/1 -F+c1930 -H > a.cpt
	gmt plot @mississippi.txt -R0/1/0/50 -JX15c/7c -W1.5p,auto -Bxaf -Byaf+l"10@+3@+ m@+3@+/s" -BWSrt+t"Mississippi river annual discharge" -i0,1+s1e-3 -wy -g0z0.05+n --COLOR_SET=a.cpt
	cat > neis.legend << END
H 16 1 Year
A a.cpt
D 0.1 1p
N 6
V 0 1p
S 0.1i c 0.15i z=1930 0.25p 0.3i 1930
S 0.1i c 0.15i z=1931 0.25p 0.3i 1931
S 0.1i c 0.15i z=1932 0.25p 0.3i 1932
S 0.1i c 0.15i z=1933 0.25p 0.3i 1933
S 0.1i c 0.15i z=1934 0.25p 0.3i 1934
S 0.1i c 0.15i z=1935 0.25p 0.3i 1935
S 0.1i c 0.15i z=1936 0.25p 0.3i 1936
S 0.1i c 0.15i z=1937 0.25p 0.3i 1937
S 0.1i c 0.15i z=1938 0.25p 0.3i 1938
S 0.1i c 0.15i z=1939 0.25p 0.3i 1939
S 0.1i c 0.15i z=1940 0.25p 0.3i 1940
END
gmt legend -DJBC+o0/0.4i+w15c -F+p+i+glightyellow+s neis.legend
gmt end

I do not know of a way to specify the pen color in legend from the colormap lookup. @pwessel, do you think this could be a feature request?

Busy this morning with Chair stuff. yes, suitable for a feature request. Need to consider all the various ways one might want to assign colors here.

I used a rectangle instead S 0.1i r 0.4c,0,1c z=1930 0.25p 0.3i 1930. Now I just need to remove the outline.

1 Like