Time axis, issues with setting tick positions, tick label formatting and placement.

Open
#8,937 12 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
c

Research direction

Start by reproducing the issue with the four GMT basemap commands and compare their tick positions, label formats, and alignment with the gnuplot example. Read the GMT handling for -Bxa/-Bxf time axes and FORMAT_DATE_MAP/FORMAT_TIME_PRIMARY_MAP. Done means the requested 14-day positions, "%b %d"-style labels, and centered placement behave consistently without extra or misplaced labels.

Written by the indexing model from the issue text.

Description

bug discussion

I wanted to set X axis as time, set major ticks every 2 weeks (14 days), and format tick labels as "%b %d", aligned (centered) exactly at the axis tick positions. My example data range is a bit shorter than 2 months.

In short: I want to have time tick placement, labels format specs and label alignment as shown in my gnuplot example. I am not getting this with GMT. See more below.

My gnuplot code and figure is presented to demonstrate what I want and how it is specified. Further down I posted what I was able to get using GMT, the code and the results that I don't like at all - mostly erratic tick positions, misaligned tick labels, and label formats not respecting the requested specifications.

I want to get the same result I get with gnuplot. Gnuplot apparently (naively) counts 2-week intervals starting from the epoch. This way major ticks appear at 2019-02-21 etc. These major tick positions are a whole number of 2-week periods away from the epoch of 1970-01-01. I want to get the same tick positions and tick labels aligned the same way in GMT.

NB a standard way of specifying tick label format using C strftime format specifiers. A significant advantage for the user (me) that tick label of types Time and Date become essentially the same with this approach. Time/Date formatting seems two different things with GMT. It is not clear why it is so and what benefits it brings. The documentation and examples are scarce and scattered across several different places.

NB 1 Gnuplot's approach to the time interval/tick placement implies that regardless of the specified time interval all the time ticks and labels always remain at exactly the same positions.

My gnuplot code:

set term pngcairo enhanced size 800,80 font "Helvetica,14"
set output "gnuplot.png"
set xdata time
set timefmt "%Y-%m-%d"
set xrange ["2019-02-15" to "2019-04-08"]
set yrange [0 to 1]
unset ytics
set xtics 3600*24*14 nomirror out
set format x "%b %d"
set border 1
plot 0/0 notitle

Plot:
Image

Now to my GMT trials and the results.

When I specify -Bxa14Rf7R the following --FORMAT_DATE_MAP="o dd" is not respected, label format is just the date of month, labels are misaligned and printed a bit away from the ticks:

gmt basemap -R2019-02-15T/2019-04-08T/-20/+20 -JX10c -BS -Bxa14Rf7R -png R --FORMAT_DATE_MAP="o dd" --FORMAT_TIME_PRIMARY_MAP=abbrev
Image

When I specify -Bxa2Uf1U --FORMAT_DATE_MAP="o dd" --FORMAT_TIME_PRIMARY_MAP=abbrev label format is correct but the labels are misaligned and printed far away from the ticks:

gmt basemap -R2019-02-15T/2019-04-08T/-20/+20 -JX10c -BS -Bxa2Uf1U -png U --FORMAT_DATE_MAP="o dd" --FORMAT_TIME_PRIMARY_MAP=abbrev
Image

When I specify -Bxa14Df7D --FORMAT_DATE_MAP="o dd" --FORMAT_TIME_PRIMARY_MAP=abbrev I get extra label at Apr 01 right on top of Mar 29, plus the labels are misaligned, that is, not centered exactly at the tick positions:

gmt basemap -R2019-02-15T/2019-04-08T/-20/+20 -JX10c -BS -Bxa14Df7D -png D --FORMAT_DATE_MAP="o dd" --FORMAT_TIME_PRIMARY_MAP=abbrev
Image

With -Bxa14Df7D --FORMAT_DATE_MAP="o dd" --FORMAT_TIME_PRIMARY_MAP=abbrev i get essentially the same labels as before: only date is printed, aligned away from the tick positions. The requested abbreviated month name is just disregarded:

gmt basemap -R2019-02-15T/2019-04-08T/-20/+20 -JX10c -BS -Bxa14df7d -png d --FORMAT_DATE_MAP="o dd" --FORMAT_TIME_PRIMARY_MAP=abbrev
Image

I want in principle to have time tick placement labels and formatting as in gnuplot. This implies tick labels centered exactly at the tick positions by default (interval labels centered at the center of the interval), standard label format specifiers and standard tick position evaluation as in gnuplot, that is, all tick positions relative to the epoch.

Congrats and thanks to all those who managed to read that far down.

Dominant language
C
Stars
997
Forks
420
Avg merge
13h 27m
Merged PRs (30d)
47

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from GenericMappingTools/gmt

All issues in GenericMappingTools/gmt

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.