# Fixed width bars in histogram

**URL:** <https://forum.generic-mapping-tools.org/t/fixed-width-bars-in-histogram/4407>\
**Category:** Q&A\
**Tags:** gmt\
**Created:** [November 7, 2023, 9:39am UTC](https://forum.generic-mapping-tools.org/t/fixed-width-bars-in-histogram/4407 "2023-11-07T09:39:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jessej18](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/jessej18/32/3752_2.png) [@jessej18](https://forum.generic-mapping-tools.org/u/jessej18)\
**Post date:** [November 7, 2023, 9:39am UTC](https://forum.generic-mapping-tools.org/t/fixed-width-bars-in-histogram/4407/1 "2023-11-07T09:39:09Z")

</div>

I would like to create a histogram based on custom bin boundaries (through a file) but with each bar having a fixed width regardless of the x-range implied by the given bin edge values. In this specific case I happen to be following the 1 2 5 10 20 50… sequence, setting the x-axis to log scale. The bars are not terrible, but still different widths. Is there anyway to override the scaling calculated internally? I tried -EXc: that fixes the _spacing_ of the bars but not the _width_ (in 6.4.0) despite the wording in the Documentation for the histogram Module (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:** [November 7, 2023, 10:24am UTC](https://forum.generic-mapping-tools.org/t/fixed-width-bars-in-histogram/4407/2 "2023-11-07T10:24:46Z")

</div>

Could you provide a small test file and you command so we can reproduce and possibly fix any issue?

---

<div class="post-metadata">

**Author:** ![jessej18](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/jessej18/32/3752_2.png) [@jessej18](https://forum.generic-mapping-tools.org/u/jessej18)\
**Post date:** [November 7, 2023, 10:48am UTC](https://forum.generic-mapping-tools.org/t/fixed-width-bars-in-histogram/4407/3 "2023-11-07T10:48:17Z")

</div>

I have tried with/without -E (and with/without log option) using the following files and gmt calls:

[FatalTsunamiShipDensity.dat](https://forum.generic-mapping-tools.org/uploads/short-url/veSWxEzlAYl0M402ofjw0cspaZU.dat) (720 Bytes) [ShipDensity.dat](https://forum.generic-mapping-tools.org/uploads/short-url/tG2GDFL0qRBXGeNdLTBfIx7ffLM.dat) (14.5 KB) [ship\_density\_hist\_bins.dat](https://forum.generic-mapping-tools.org/uploads/short-url/aFdkkSGSYlApKM4YBbZtbjW1BgF.dat) (61 Bytes)

gmt begin myplot pdf  
gmt histogram ShipDensity.dat -Tship\_density\_hist\_bins.dat -JX10cl/5c -G180 -W1,black -Bx2+l"# of Ships" -Bya20+l"Count" -R0.1/5000/0/170 -E1c  
gmt histogram FatalTsunamiShipDensity.dat -Tship\_density\_hist\_bins.dat -JX10cl/5c -Gred -W0.5,180/0/0 -E1c -R0.1/5000/0/170  
gmt end show

---

<div class="post-metadata">

**Author:** ![yvonnefroehlich](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/yvonnefroehlich/32/5064_2.png) [@yvonnefroehlich](https://forum.generic-mapping-tools.org/u/yvonnefroehlich)\
**Post date:** [November 7, 2023, 1:08pm UTC](https://forum.generic-mapping-tools.org/t/fixed-width-bars-in-histogram/4407/4 "2023-11-07T13:08:22Z")

</div>

Hello @jessej18,

Welcome to the GMT forum 🙂!

I ran your code example and got this output figure:

 ![myplot_E1c](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/8/87acda70cc4827525c1cbad72fb786950d4f8748.png)

For me, it looks like the bars appear to have different widths because they are overlapping. If a semi-transparent fill color is used for the bars (i.e. `-G180@50` and `-Gred@50`), I get this output figure:

 ![myplot_E1c_semitrans](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/5/5be4d90f70154b3cd53a7aa7c46d395923ae121d.png)

In this figure one can see that all bars have the same width.  
Maybe using thinner bars is a solution here? E.g., `-E0.5c` instead of `-E1c`, gives this output figure:

 ![myplot_E0.5c](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/2/2db8f815545710313cb6bb236ef6e48179f51c9b.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:** [November 7, 2023, 1:29pm UTC](https://forum.generic-mapping-tools.org/t/fixed-width-bars-in-histogram/4407/5 "2023-11-07T13:29:00Z")

</div>

If you want variable width bars then you have to use plot -Sb and read the width from 3rd column in file. Or fiddle with -Sr for rectangles.

---

<div class="post-metadata">

**Author:** ![jessej18](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/jessej18/32/3752_2.png) [@jessej18](https://forum.generic-mapping-tools.org/u/jessej18)\
**Post date:** [November 7, 2023, 1:30pm UTC](https://forum.generic-mapping-tools.org/t/fixed-width-bars-in-histogram/4407/6 "2023-11-07T13:30:42Z")

</div>

Huh. You are correct. I think I must have been thrown off by the variable spacing in this mode, which made it look like the widths were still different (because the edges had different overlaps). Thank you.

---

<div class="post-metadata">

**Author:** ![jessej18](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/jessej18/32/3752_2.png) [@jessej18](https://forum.generic-mapping-tools.org/u/jessej18)\
**Post date:** [November 7, 2023, 1:32pm UTC](https://forum.generic-mapping-tools.org/t/fixed-width-bars-in-histogram/4407/7 "2023-11-07T13:32:04Z")

</div>

Good tip. I will look at those options and see if they give me the “look” I want more easily. Thanks Paul
