# Incoherent gridline behaviour

**URL:** <https://forum.generic-mapping-tools.org/t/incoherent-gridline-behaviour/1319>\
**Category:** Q&A\
**Created:** [February 8, 2021, 10:00pm UTC](https://forum.generic-mapping-tools.org/t/incoherent-gridline-behaviour/1319 "2021-02-08T22:00:08Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![PlanetGus](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/planetgus/32/303_2.png) [@PlanetGus](https://forum.generic-mapping-tools.org/u/PlanetGus)\
**Post date:** [February 8, 2021, 10:00pm UTC](https://forum.generic-mapping-tools.org/t/incoherent-gridline-behaviour/1319/1 "2021-02-08T22:00:08Z")

</div>

> On gmt v. 6.2.0\_bb0b2d9\_2020.12.14 with macOS Big Sur

Hi,  
I’m trying to plot a time-series with two set of annotations for the y-axis using daily data.  
The primary axis is supposed to :

- **not** annotate
- tick every months
- add a gridline every months

The secondary axis is supposed to :

- annotate every year
- tick every year
- add a gridline every year

I hoped to have a thicker line for the secondary grid lines, but if it’s too complicated, I can also not use it as it is redundant with the primary ones (once per year).

At any rate, at first I tried this :

```auto
gmt grdimage ${region} ${projection} $FILE?var -Bxa20f10g10 -Bpyf1Og1O -Bsya1Yf1Yg1Y -BWSen

```

as well as `12O` `12o` `1y`…

The annotations are fine, the ticks seem to be too … but the grid lines are either shifted and inconsistently spaced or plotted daily (or so it seems).

Do you have a suggestion ?

See picture :  
On left : `-Bpyf1o -Bsya1Y`  
On right : `-Byf1og12y`

 ![Screenshot 2021-02-08 at 17.05.23](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/1X/915a7cd22ab18ae6651f74a7e86f03198d0bf7ea.png)

---

<div class="post-metadata">

**Author:** ![MarceloBanik](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/marcelobanik/32/479_2.png) [@MarceloBanik](https://forum.generic-mapping-tools.org/u/MarceloBanik)\
**Post date:** [February 8, 2021, 11:14pm UTC](https://forum.generic-mapping-tools.org/t/incoherent-gridline-behaviour/1319/2 "2021-02-08T23:14:47Z")

</div>

using psbasemap appears to work:

> gmt psbasemap -R0/100/2020-06-01T/2021-06-01T -JX10c/10cT -Bxa20f10g10 -Bpyf1Og1O -Bsya1Yf1Yg1Y -BWSen --MAP\_GRID\_PEN\_PRIMARY=thinner,grey --MAP\_GRID\_PEN\_SECONDARY=thin,black -png test
> 
> ![test](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/1X/fb1cda01a2434785e8188fc1b8f440cef7713944.png)  
> I didn’t expect that grdimage will do something different, but I didn’t have any file here to try.  
> Is it possible to share some simple data to test it?  
> using gmt 6.2.0\_68e0098\_2021.01.19

---

<div class="post-metadata">

**Author:** ![PlanetGus](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/planetgus/32/303_2.png) [@PlanetGus](https://forum.generic-mapping-tools.org/u/PlanetGus)\
**Post date:** [February 8, 2021, 11:32pm UTC](https://forum.generic-mapping-tools.org/t/incoherent-gridline-behaviour/1319/3 "2021-02-08T23:32:39Z")

</div>

Sure …  
Sorry for the delay … I had to extract a sample and upload it on a tiers service :

> **[Dropbox](https://www.dropbox.com/s/g73jngb2p0zrzbj/sample_data.nc?dl=0)**

The data are Sea-Surface Temperature averaged in the Pacific equatorial band (so it has the dimension of longitude x time)  
lon1 = 110  
lonN = 280  
time1 = 1980-01-01  
timeN = 1984-01-01 (I think , I truncated it bluntly)

the variable to plot is eqb\_nc\_sst

---

<div class="post-metadata">

**Author:** ![MarceloBanik](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/marcelobanik/32/479_2.png) [@MarceloBanik](https://forum.generic-mapping-tools.org/u/MarceloBanik)\
**Post date:** [February 9, 2021, 1:22am UTC](https://forum.generic-mapping-tools.org/t/incoherent-gridline-behaviour/1319/4 "2021-02-09T01:22:08Z")

</div>

appears that it get a wrong TIME\_EPOCH:

> $ gmt grdinfo sample\_data.nc  
> grdinfo [WARNING]: TIME\_EPOCH format is invalid. Default assumed.  
> grdinfo [WARNING]: A correct format has the form [-]yyyy-mm-ddThh:mm:ss[.xxx]  
> grdinfo [WARNING]: or (using ISO weekly calendar) yyyy-Www-dThh:mm:ss[.xxx]  
> grdinfo [WARNING]: An example of a correct format is: 2000-01-01T12:00:00  
> grdinfo [WARNING]: Time units [days since 0000-01-00 00:00:00.0 +0000]] in grid not recognized, defaulting to gmt.conf settings.  
> sample\_data.nc: Title:  
> sample\_data.nc: Command:  
> sample\_data.nc: Remark:  
> sample\_data.nc: Gridline node registration used [Cartesian grid]  
> sample\_data.nc: Grid file format: nf = GMT netCDF format (32-bit float), CF-1.7  
> sample\_data.nc: x\_min: 110 x\_max: -80 x\_inc: 0.25 name: longitude n\_columns: 681  
> sample\_data.nc: y\_min: 0 y\_max: 126144000 y\_inc: 86400 name: time [days since 0000-01-00 00:00:00.0 +0000] n\_rows: 1461  
> sample\_data.nc: v\_min: 0 v\_max: 0 name: eqb\_nc\_sst  
> sample\_data.nc: scale\_factor: 1 add\_offset: 0  
> sample\_data.nc: format: classic

I try to convert to xyz and back to grid to set the TIME\_EPOCH, but I get only NaN for the Z value:

> gmt grd2xyz “sample\_data.nc?eqb\_nc\_sst” | gmt xyz2grd -R110/280/1980-01-01T/1984-01-01T -I0.25/86400 -f0f,1t -Gtest.nc

Anyway, to test the grid, I could use this test.nc garbage:

> gmt makecpt -Crainbow \> test.cpt  
> gmt grdimage test.nc -R110/280/1981-01-01T/1983-01-01T -JX10c/10cT -Ctest.cpt -Bxa20f10g10 -Bpyf1Og1O -Bsya1Yf1Yg1Y -BWSen --MAP\_GRID\_PEN\_PRIMARY=thinner,grey --MAP\_GRID\_PEN\_SECONDARY=thin,black -png test

appears that the grid is ok, a primary every months and a secondary every year:

 ![test](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/1X/997628f9455fbe535cb9d24df89a01283113987f.png)

what command (including values) are you using?  
It could be useful to know the gmt defaults that you are using.

---

<div class="post-metadata">

**Author:** ![PlanetGus](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/planetgus/32/303_2.png) [@PlanetGus](https://forum.generic-mapping-tools.org/u/PlanetGus)\
**Post date:** [February 9, 2021, 1:35am UTC](https://forum.generic-mapping-tools.org/t/incoherent-gridline-behaviour/1319/5 "2021-02-09T01:35:30Z")

</div>

Hum weird,

maybe the time goes from 0 to length(time)  
with

```auto
gmt gmtset TIME_EPOCH 1980-01-01

```

---

<div class="post-metadata">

**Author:** ![MarceloBanik](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/marcelobanik/32/479_2.png) [@MarceloBanik](https://forum.generic-mapping-tools.org/u/MarceloBanik)\
**Post date:** [February 9, 2021, 10:33am UTC](https://forum.generic-mapping-tools.org/t/incoherent-gridline-behaviour/1319/6 "2021-02-09T10:33:40Z")

</div>

after some adjust in the netcdf file and using:

> gmt makecpt -T294/304/1 \> test.cpt

resulting:

 ![test](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/1X/57ca54e92f58bdacd140e4ec3fb9adaa17ba9bb8.png)  
It appears to me that the grid is ok, a primary every months and a secondary every year.

---

<div class="post-metadata">

**Author:** ![PlanetGus](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/planetgus/32/303_2.png) [@PlanetGus](https://forum.generic-mapping-tools.org/u/PlanetGus)\
**Post date:** [February 9, 2021, 3:15pm UTC](https://forum.generic-mapping-tools.org/t/incoherent-gridline-behaviour/1319/7 "2021-02-09T15:15:25Z")

</div>

Using the same kind of data (relative time `TIME_EPOCH 1980-01-01`)

```auto
gmt grdimage -R$lon1a/$lon1b/$day1/$day2 -JX${w1}cd/-${height}ct $FILE?eqb_cl_sst -Bxa20f10g10 -Bpyf1O -Bsya1Yf1Y -BWSen 

```

Gives expected result.

Any `g` addition to either `Bpy` or `Bsy` fill the plot with gridlines every day (unit) instead of wanted `O` or `Y`.  
Could it be related to the issue I reported with `math` [on Github](https://github.com/GenericMappingTools/gmt/issues/4771#issue-804042384) ?

---

<div class="post-metadata">

**Author:** ![MarceloBanik](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/marcelobanik/32/479_2.png) [@MarceloBanik](https://forum.generic-mapping-tools.org/u/MarceloBanik)\
**Post date:** [February 9, 2021, 4:02pm UTC](https://forum.generic-mapping-tools.org/t/incoherent-gridline-behaviour/1319/8 "2021-02-09T16:02:57Z")

</div>

here I didn’t have ploblems do add g to either Bpy or Bsy, as I showed before.  
I think I get your example right here:

> $ gmt math -o0 -T1980-01-01T/2019-12-31T/4y T =  
> 1980-01-01T00:00:00.000000000  
> 1984-01-01T00:00:00.000000000  
> 1988-01-01T00:00:00.000000000  
> 1992-01-01T00:00:00.000000000  
> 1996-01-01T00:00:00.000000000  
> 2000-01-01T00:00:00.000000000  
> 2004-01-01T00:00:00.000000000  
> 2008-01-01T00:00:00.000000000  
> 2012-01-01T00:00:00.000000000  
> 2016-01-01T00:00:00.000000000

could you share your defaults?

> gmt defaults \> defaults.txt

What I have here is:  
[defaults.txt](https://forum.generic-mapping-tools.org/uploads/short-url/rZzvM6HJ7Q573yUYZcmsjZeEYtj.txt) (5.1 KB)  
Note that I used “T” in -JX10c/10cT to specify a time axes and appears that you used “t”. Could it be the problem? What exactly is your -JX${w1}cd/-${height}ct ?

---

<div class="post-metadata">

**Author:** ![PlanetGus](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/planetgus/32/303_2.png) [@PlanetGus](https://forum.generic-mapping-tools.org/u/PlanetGus)\
**Post date:** [February 9, 2021, 4:35pm UTC](https://forum.generic-mapping-tools.org/t/incoherent-gridline-behaviour/1319/9 "2021-02-09T16:35:53Z")

</div>

> [@MarceloBanik](#):
>
> What exactly is your -JX${w1}cd/-${height}ct

These are numeric values calculated with `bc` … not an issue really

I see that you’re using the “stable” version (GMT6.1), maybe a bug in dev6.2 ?

I’ll take a moment this afternoon to compare your default file … thanks 🙂

---

<div class="post-metadata">

**Author:** ![MarceloBanik](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/marcelobanik/32/479_2.png) [@MarceloBanik](https://forum.generic-mapping-tools.org/u/MarceloBanik)\
**Post date:** [February 9, 2021, 4:50pm UTC](https://forum.generic-mapping-tools.org/t/incoherent-gridline-behaviour/1319/10 "2021-02-09T16:50:54Z")

</div>

working with gmt 6.2.0\_68e0098\_2021.01.19:

> $ gmtswitch 6.2.0;gmt --version;gmt math -o0 -T1980-01-01T/2019-12-31T/4y T =  
> 6.2.0\_68e0098\_2021.01.19  
> 1980-01-01T00:00:00.000000000  
> 1984-01-01T00:00:00.000000000  
> 1988-01-01T00:00:00.000000000  
> 1992-01-01T00:00:00.000000000  
> 1996-01-01T00:00:00.000000000  
> 2000-01-01T00:00:00.000000000  
> 2004-01-01T00:00:00.000000000  
> 2008-01-01T00:00:00.000000000  
> 2012-01-01T00:00:00.000000000  
> 2016-01-01T00:00:00.000000000

---

<div class="post-metadata">

**Author:** ![maxrjones](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/maxrjones/32/2698_2.png) [@maxrjones](https://forum.generic-mapping-tools.org/u/maxrjones)\
**Post date:** [February 9, 2021, 5:11pm UTC](https://forum.generic-mapping-tools.org/t/incoherent-gridline-behaviour/1319/11 "2021-02-09T17:11:09Z")

</div>

I think you’re probably using different OS’s. When I build 6.2.0\_68e0098\_2021.01.19 on MacOS `gmt math -o0 -T1980-01-01T/2019-12-31T/4y T =` does not work and gives the same bug as reported recently on GitHub.

---

<div class="post-metadata">

**Author:** ![PlanetGus](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/planetgus/32/303_2.png) [@PlanetGus](https://forum.generic-mapping-tools.org/u/PlanetGus)\
**Post date:** [February 9, 2021, 6:05pm UTC](https://forum.generic-mapping-tools.org/t/incoherent-gridline-behaviour/1319/12 "2021-02-09T18:05:28Z")

</div>

@maxrjones :  
back to the `-Bg options` problem, do you think it is also an OS issue ?

Nothing really unusual between my default parameters / script and the ones @MarceloBanik shared to help me.

---

<div class="post-metadata">

**Author:** ![MarceloBanik](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/marcelobanik/32/479_2.png) [@MarceloBanik](https://forum.generic-mapping-tools.org/u/MarceloBanik)\
**Post date:** [February 9, 2021, 7:31pm UTC](https://forum.generic-mapping-tools.org/t/incoherent-gridline-behaviour/1319/13 "2021-02-09T19:31:26Z")

</div>

gmt grdimage test.nc -R110/280/1981-11-01T/1982-02-01T -JX10cd/10cT -Ctest.cpt -Bxa20f10g10 -Bpyf1Og1O -Bsya1Yf1Yg1Y -BWSen --MAP\_GRID\_PEN\_PRIMARY=thinner,grey --MAP\_GRID\_PEN\_SECONDARY=thin,black --TIME\_INTERVAL\_FRACTION=0.1 -png test1  
results:

 ![test1](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/1X/09ce472fad1bbebd9186d2c59177c908a5f00c4d.png)

changing -R110/280/1981-11-01T/1982-02-01T to -R110/280/373420800/381369600

> gmt grdimage test.nc -R110/280/373420800/381369600 -JX10cd/10cT -Ctest.cpt -Bxa20f10g10 -Bpyf1Og1O -Bsya1Yf1Yg1Y -BWSen --MAP\_GRID\_PEN\_PRIMARY=thinner,grey --MAP\_GRID\_PEN\_SECONDARY=thin,black --TIME\_INTERVAL\_FRACTION=0.1 --TIME\_UNIT=s --TIME\_EPOCH=1970-01-01T00:00:00 -png test2

results:

 ![test1](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/1X/09ce472fad1bbebd9186d2c59177c908a5f00c4d.png)  
changing -JX10cd/10cT to -JX10cd/10ct

> gmt grdimage test.nc -R110/280/373420800/381369600 -JX10cd/10ct -Ctest.cpt -Bxa20f10g10 -Bpyf1Og1O -Bsya1Yf1Yg1Y -BWSen --MAP\_GRID\_PEN\_PR  
> IMARY=thinner,grey --MAP\_GRID\_PEN\_SECONDARY=thin,black --TIME\_INTERVAL\_FRACTION=0.1 --TIME\_UNIT=s --TIME\_EPOCH=1970-01-01T00:00:00 -png test3

results:

 ![test3](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/1X/89d919cc7cc00e59a043f4612b656735a1b592e7.png)  
what I suspect is a grid every day.  
Then I suspect you could try use -JX${w1}cd/-${height}cT

---

<div class="post-metadata">

**Author:** ![PlanetGus](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/planetgus/32/303_2.png) [@PlanetGus](https://forum.generic-mapping-tools.org/u/PlanetGus)\
**Post date:** [February 9, 2021, 8:13pm UTC](https://forum.generic-mapping-tools.org/t/incoherent-gridline-behaviour/1319/14 "2021-02-09T20:13:40Z")

</div>

> [@MarceloBanik](#):
>
> Then I suspect you could try use -JX${w1}cd/-${height}cT

That works !  
Thanks.

It is strange because the script used to work fine in GMT5… I guess modern mode is more rigorous about this. 🤔

---

<div class="post-metadata">

**Author:** ![MarceloBanik](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/marcelobanik/32/479_2.png) [@MarceloBanik](https://forum.generic-mapping-tools.org/u/MarceloBanik)\
**Post date:** [February 9, 2021, 8:59pm UTC](https://forum.generic-mapping-tools.org/t/incoherent-gridline-behaviour/1319/15 "2021-02-09T20:59:40Z")

</div>

I think it should have worked with -JX${w1}cd/-${height}ct.  
So it appears to be a bug.

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [February 9, 2021, 10:01pm UTC](https://forum.generic-mapping-tools.org/t/incoherent-gridline-behaviour/1319/16 "2021-02-09T22:01:35Z")

</div>

I dont think it is a but. Capital T is required if you want an axis to be temporal.

---

<div class="post-metadata">

**Author:** ![PlanetGus](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/planetgus/32/303_2.png) [@PlanetGus](https://forum.generic-mapping-tools.org/u/PlanetGus)\
**Post date:** [February 9, 2021, 10:06pm UTC](https://forum.generic-mapping-tools.org/t/incoherent-gridline-behaviour/1319/17 "2021-02-09T22:06:44Z")

</div>

This is weird though

With `-J[...]ct` (and timestamps given relative to TIME\_EPOCH) everything works except for `-Byg[..]` (no problem with x). The gridlines are systematically plotted at “unit”.

With `-J[...]cT` (and timestamps given in absolute format) everything works.

---

<div class="post-metadata">

**Author:** ![MarceloBanik](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/marcelobanik/32/479_2.png) [@MarceloBanik](https://forum.generic-mapping-tools.org/u/MarceloBanik)\
**Post date:** [February 9, 2021, 10:58pm UTC](https://forum.generic-mapping-tools.org/t/incoherent-gridline-behaviour/1319/18 "2021-02-09T22:58:02Z")

</div>

from [https://docs.generic-mapping-tools.org/latest/gmt.html#r-full](https://docs.generic-mapping-tools.org/latest/gmt.html#r-full)  
For calendar time coordinates you may either give (a) relative time (relative to the selected TIME\_EPOCH and in the selected TIME\_UNIT; append t to -JX|x)  
Then I think that  
-R110/280/373420800/381369600 -JX10cd/10ct --TIME\_UNIT=s --TIME\_EPOCH=1970-01-01T00:00:00  
should have worked.

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [February 10, 2021, 12:22am UTC](https://forum.generic-mapping-tools.org/t/incoherent-gridline-behaviour/1319/19 "2021-02-10T00:22:19Z")

</div>

I agree that it says that in the docs. I will try to learn why the 1O gets (probably) converted to double and gives 1 (second).

---

<div class="post-metadata">

**Author:** ![PlanetGus](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/planetgus/32/303_2.png) [@PlanetGus](https://forum.generic-mapping-tools.org/u/PlanetGus)\
**Post date:** [February 10, 2021, 10:51pm UTC](https://forum.generic-mapping-tools.org/t/incoherent-gridline-behaviour/1319/20 "2021-02-10T22:51:41Z")

</div>

@pwessel, I’m not sure we’re talking about the same thing…

I have 2 set of data where time starts at 0 (relative to `TIME_EPOCH 1980-01-01` , `TIME_UNIT d`)

- A netcdf file (`grdimage`)
- A text file (`plot`)

When I try to plot my data I do

```auto
# Case 1 (wanted)
gmt grdimage -R0/360/1980-01-01/1984-01-01 -JX10cd/-10ct file.nc"?var" -Bxa20f10g10 -Bpyf1og1o -Bsya1yf1yg1y -BWSen
gmt plot tmp.txt -W2,black -Gred -Sc -t50 

# Case 2 (not ideal)
gmt grdimage -R0/360/0/1461 -JX10cd/-10ct file.nc"?var" -Bxa20f10g10 -Bpyf1og1o -Bsya1yf1yg1y -BWSen
gmt plot tmp.txt -W2,black -Gred -Sc -t50 

# Case 3
gmt grdimage -R0/360/1980-01-01/1984-01-01 -JX10cd/-10cT file.nc"?var" -Bxa20f10g10 -Bpyf1og1o -Bsya1yf1yg1y -BWSen
gmt plot tmp.txt -W2,black -Gred -Sc -t50 

```

## Case 1 : JX()d/()t (x : geo-degrees , y: relative time)

`-R` is given with absolute time regardless.  
Both `grdimage` and `plot` are displayed as expected, except for the grid lines on y-Primary and y-Secondary axis. They are too dense and completely fill the picture (TIME\_UNIT probably switched in seconds)  
Apart from the grid line, everything is correct. (NB x-axis grid lines are fine too)

## Case 2 : same

`-R` is given with relative time.  
It makes no difference compared to **Case 1** , so I’d rather stick to the **Case 1** as the input format doesn’t require additional calculation.

## Case 3 : JX()d/()T (x : geo-degrees , y: absolute time)

-R is given with absolute time.  
`grdimage` is still fine. The gridlines appear correctly, but `plot` is off-grid.

[Next page](https://forum.generic-mapping-tools.org/t/incoherent-gridline-behaviour/1319.md?page=2)
