Fixed width bars in histogram

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?).

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

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

FatalTsunamiShipDensity.dat (720 Bytes) ShipDensity.dat (14.5 KB) ship_density_hist_bins.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

Hello @jessej18,

Welcome to the GMT forum :slightly_smiling_face:!

I ran your code example and got this output figure:

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:

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:

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.

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.

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