There are problems with the unit of month, because a month is a variable beast. Either 28, 29, 30 or 31 days. So maybe your “inelegant” solution is better?
Also, look at the GMT_LANGUAGE options so you can make plots with a truly international flavour.
My problem is not really about the xticks, but really on how to wrap the values around the year…
Meaning the first tick indeed starts in May but with the value associated to the 5th month (not the 1st value which is January).
Your solution associates the January “value” to May “tick”.
I didn’t notice that - I was so focused on the labels!
So the months are simply labelled 1 = Jan, 2 = Feb and so on? You want January to appear after May. For this to make sense on a time axis, January has to have a larger time value than may. I can think of two ways of doing this:
Convert your months to proper dates:
2020-05-01
2020-06-01
.
.
.
2021-01-01
2021-02-02 and so on
Add 12 to January through April, so your time series goes like this:
13 yjan
14 yfeb
15 ymar
16 yapr
5 ymay
6 yjun
.
.
.
12 ydec
And use something like the code I pasted above, but set the EPOCH to 2020-01-01 and plot the region 2020-05-01/2021-04-30/…
I use your idea of adding 12 to the month number, here are the different steps for future reference (If @pwessel find the solution useful, I might post-it in the ShowCase section) :
gmt select file.nc?x/y -R1/4/0/100 > TS.txt #extract January to April
gmt math TS.txt -C0 12 ADD = TS.txt #add 12 to first column
gmt select file.nc?x/y -R5/12/0/100 >> TS.txt #append May to December
Now I have a text file like this :
Month
Value
13 (J)
y1
14 (F)
y2
15 (M)
y3
16 (A)
y4
5 (M)
y5
6 (J)
y6
…
…
12 (D)
y12
Then I assigned for each x_value (month number) the letter :
cat << EOF > lab.txt
4.5 ig M
5.5 ig J
6.5 ig J
7.5 ig A
8.5 ig S
9.5 ig O
10.5 ig N
11.5 ig D
12.5 ig J
13.5 ig F
14.5 ig M
15.5 ig A
16.5 ig
EOF
(0.5 added to center the letter between two ticks)
Finally I plot the bar graph :
gmt begin bar_graph
gmt subplot begin 2x2 -Fs10c -M.5c -A(a)+JTL+o-1c/.25c -BWSen
gmt subplot set
gmt plot -R4/17/0/100 TS.txt -Sb1u -Bxclab.txt -Byaf+l"Frequency (%)" -Gred -Wthinnest,black -t50
gmt legend -DjTR+w4c+o5p/5p -F+r4p+pthinnest,gray+gwhite <<- END
S - c 0.25c red thinnest - legend_txt
END
echo titre_txt | gmt text -F+cTR -D0c/0.6c -N
gmt subplot end
gmt end show
I think this is a reasonable solution. A time axis that starts in May and wraps around back to January is not a time axis, and converting the coordinates to actual absolute time is not going to help here.
However, what I can imagine is someone wanting to make a histogram of time-series data over many years and wanting to show the distribution versus month (e.g., average precipitation per month over the last 10 years). Given that the data are real time-series it would be nice if histogram had some option to make the bins periodic over the year so the data would stack. But then we still would be back to how to annotate a now non-absolute time with labels like months, I will ponder these challenges to see if I can think of a simpler solution.
No, definitively not that via -R (for lots of under-the-hood reasons). This issue is a little bit like longitudes which are inherently periodic and plotting (370, 0) lands on the same spot as (10,0). Here the period is implicit (360) but for a general case the period would need to be specified. This would be a GMT-wide solution, but not sure if your single example would justify such a development. I am more open to a histogram option to allow such things since there we may have a legitimate need (e.g., averaging/stacking tiime-series over many years). Your data set is a bit artificial and hand-made in this case. Is it averages over many years or just a single year (in which case absolute time would work)?
Over many years in that case … (histogram-ish matlab function using accumarray)
…
And what about simply a module that would allow to manipulate files the way I did ? (concatenate)