# Histogram with new -w cyclic option

**URL:** <https://forum.generic-mapping-tools.org/t/histogram-with-new-w-cyclic-option/1470>\
**Category:** Q&A\
**Created:** [March 18, 2021, 6:58pm UTC](https://forum.generic-mapping-tools.org/t/histogram-with-new-w-cyclic-option/1470 "2021-03-18T18:58:54Z")\
**Posts on this page:** 18\
**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:** [March 18, 2021, 6:58pm UTC](https://forum.generic-mapping-tools.org/t/histogram-with-new-w-cyclic-option/1470/1 "2021-03-18T18:58:54Z")

</div>

Hi ,

I have a file containing 1 column with absolute times :

```auto
> cat test.txt
1980-01-09T09:00:00
1980-01-29T03:00:00
1980-02-14T06:00:00
...
2016-03-13T15:00:00
2016-09-17T15:00:00
2016-10-13T06:00:00
...

```

I want to plot an histogram with a `frequency in y-axis` and `months in x-axis` using this command :

```auto
gmt begin test01
gmt histogram -JX10c -Ttest.txt -Bxaf+l"Months" -Byaf+l"Frequency"+u"%" -D+r -N0 -Z1 -wa -Glightblue -Wthinnest,black
gmt end show

```

But it just gets stuck (no error, just infinite loop) :

```auto
histogram [DEBUG]: History: Process -JX10c
histogram [INFORMATION]: Processing input table data
histogram [DEBUG]: gmtapi_init_import: Passed family = Data Table and geometry = Volume
histogram [DEBUG]: gmtapi_init_import: Added 0 new sources
histogram [DEBUG]: Object ID 0 : Registered Data Table Stream 7fff88bcfe50 as an Input resource with geometry Volume [n_objects = 1]
histogram [DEBUG]: gmtapi_init_import: Added stdin to registered sources
histogram [DEBUG]: GMT_Init_IO: Returned first Input object ID = 0
histogram [DEBUG]: GMT_Begin_IO: Mode value 1 not considered (ignored)
histogram [DEBUG]: GMT_Begin_IO: Initialize record-by-record access for Input
histogram [DEBUG]: gmtapi_next_io_source: Selected object 0
histogram [INFORMATION]: Reading Data Table from Standard Input stream
histogram [DEBUG]: GMT_Begin_IO: Input resource access is now enabled [record-by-record]

```

If I add -R0/12/0/100 it doesn’t solve the bug.

Thanks

---

<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:** [March 18, 2021, 7:40pm UTC](https://forum.generic-mapping-tools.org/t/histogram-with-new-w-cyclic-option/1470/2 "2021-03-18T19:40:21Z")

</div>

I think it will work if you just do `test.txt` rather than `-Ttest.txt`. It is trying to read the data from standard input rather than your text file.

---

<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:** [March 18, 2021, 7:41pm UTC](https://forum.generic-mapping-tools.org/t/histogram-with-new-w-cyclic-option/1470/3 "2021-03-18T19:41:39Z")

</div>

You should be able to instead use `-T1` to get annual intervals

---

<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:** [March 18, 2021, 7:44pm UTC](https://forum.generic-mapping-tools.org/t/histogram-with-new-w-cyclic-option/1470/4 "2021-03-18T19:44:23Z")

</div>

Thanks Meghan,

So what’s the -T1 's for ?

---

<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:** [March 18, 2021, 7:58pm UTC](https://forum.generic-mapping-tools.org/t/histogram-with-new-w-cyclic-option/1470/5 "2021-03-18T19:58:56Z")

</div>

`-T[min/max]int` is required to set the interval for the bins (leaving off min/max implies they can be read from `-R`).

In your example, using `-wa` reformats your input data to all be in the range 0 - 12, so `-T1` will then bin them every integer which is the same as binning by months thanks to the new `-w` option. Similarly `-T3` could be used to bin by quarter.

p.s. you can use `gmt convert @test.txt -wa > output.txt ` to see what `-wa` is doing.

---

<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:** [March 18, 2021, 7:59pm UTC](https://forum.generic-mapping-tools.org/t/histogram-with-new-w-cyclic-option/1470/6 "2021-03-18T19:59:02Z")

</div>

More practical question … how do I shift the plot to be centered on Winter ?  
-wa/[phase] doesn’t work

`-E1+o6` doesn’t cycle

---

<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:** [March 18, 2021, 8:02pm UTC](https://forum.generic-mapping-tools.org/t/histogram-with-new-w-cyclic-option/1470/7 "2021-03-18T20:02:15Z")

</div>

You can use `-R` to control the center value. For example: `-R-5/7/0/8` would set the first bin to August.

---

<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:** [March 18, 2021, 8:03pm UTC](https://forum.generic-mapping-tools.org/t/histogram-with-new-w-cyclic-option/1470/8 "2021-03-18T20:03:50Z")

</div>

Awesome.  
I didn’t think about assigning negative values.  
Puuurfect 🙂

---

<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:** [March 18, 2021, 8:24pm UTC](https://forum.generic-mapping-tools.org/t/histogram-with-new-w-cyclic-option/1470/9 "2021-03-18T20:24:12Z")

</div>

## Satisfying result :

1. Transform indices from file to absolute time :

```auto
# The data of interest are in the first column of event_index.txt
# The time-step in my original file is 3 hours
gmt math -o0 -foT -C0 event_index.txt 3 MUL 3 SUB --TIME_EPOCH=1980-01-01 --TIME_UNIT=h = test.txt

```

1. Plot the annual frequency histogram centered on winter :

```auto
# First month is August, the last is July
gmt begin test01 png
gmt histogram -R-5/7/0/20 -JX10c test.txt -T1 -BWSen -Bxa1Of1O+l"Months" -Byaf+l"Frequency"+u"%" -D+r -Z1 -wa -Glightblue -Wthinnest,black --FORMAT_TIME_PRIMARY_MAP=c
gmt end

```

 ![test01](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/7/79e28dacf20be0b76a4d8a73b8f6d4c918d38839.png)

---

<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:** [March 18, 2021, 8:40pm UTC](https://forum.generic-mapping-tools.org/t/histogram-with-new-w-cyclic-option/1470/10 "2021-03-18T20:40:24Z")

</div>

Very nice! It confirms the old Wessel saying “There is nothing GMT cannot do as long as we code up what it is we want it to do”.

---

<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:** [March 18, 2021, 8:42pm UTC](https://forum.generic-mapping-tools.org/t/histogram-with-new-w-cyclic-option/1470/11 "2021-03-18T20:42:36Z")

</div>

Indeed !  
However the -N option is weird … (I don’t need it, but you might want to have a look at how it’s plotted)

---

<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:** [March 18, 2021, 8:49pm UTC](https://forum.generic-mapping-tools.org/t/histogram-with-new-w-cyclic-option/1470/12 "2021-03-18T20:49:44Z")

</div>

We have tests that use -N that looks fine, but that predates -w. If you have a strange example, then please share.

---

<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:** [March 18, 2021, 8:53pm UTC](https://forum.generic-mapping-tools.org/t/histogram-with-new-w-cyclic-option/1470/13 "2021-03-18T20:53:50Z")

</div>

Taking the example above,

- I removed `-R` (starts in January)
- I added `-N0`

 ![test01](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/2/267b68628cc9df923bb844021d99ef4add3fb90b.png)

---

<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:** [March 18, 2021, 8:58pm UTC](https://forum.generic-mapping-tools.org/t/histogram-with-new-w-cyclic-option/1470/14 "2021-03-18T20:58:13Z")

</div>

I will reluctantly agree with you that this is not the expected curve. Could you please post test.txt so I can reproduce?

---

<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:** [March 18, 2021, 8:59pm UTC](https://forum.generic-mapping-tools.org/t/histogram-with-new-w-cyclic-option/1470/15 "2021-03-18T20:59:31Z")

</div>

here you go 🙂

[test.txt](https://forum.generic-mapping-tools.org/uploads/short-url/yoKybUabavuVCJQZZCyobon9EV.txt) (9.8 KB)

---

<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:** [March 18, 2021, 9:00pm UTC](https://forum.generic-mapping-tools.org/t/histogram-with-new-w-cyclic-option/1470/16 "2021-03-18T21:00:53Z")

</div>

thank you - will try to give it a test this weekend.

---

<div class="post-metadata">

**Author:** ![suribabu](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@suribabu](https://forum.generic-mapping-tools.org/u/suribabu)\
**Post date:** [April 21, 2024, 6:04pm UTC](https://forum.generic-mapping-tools.org/t/histogram-with-new-w-cyclic-option/1470/17 "2024-04-21T18:04:36Z")

</div>

Please provide me the idea to plot the below magnitude plot, based on color indication.

 ![image](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/4/445679f11f5ae365c96d4d579b10a8ec513cbf2e.png)

---

<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:** [May 3, 2024, 2:12pm UTC](https://forum.generic-mapping-tools.org/t/histogram-with-new-w-cyclic-option/1470/18 "2024-05-03T14:12:31Z")

</div>

I would say simply `histogram` module in combination with `-C` option right ?
