How to make these histogram bars symmetric around its value?

asked 2025-07-04 09:14:23 +0200

c.p. gravatar image

updated 2025-07-05 07:45:03 +0200

How to make these (integer-valued) histogram bars symmetric?

The output of

 sage: histogram([1,1,1,1,1,1,2,1,1,2,2,2,2,4,4,3,4])

is the plot below at whose. The bar at 1 is not centered, but shifted to the right; the bar at 4 is shifted to the left; the middle ones show milder shifts, image description

My primitive solution is to replace (don't laugh) by

 histogram([.85,.85,.85,.85,.85,.85,2,.85,.85,2,2,2,2,4.15,4.15,3,4.15])

to get what I wish:

image description

How to do this properly?

edit retag flag offensive close merge delete

Comments

As far as I can tell this uses matplotlib.pyplot.hist which has the same issue, so you might want to ask the matplotlib people.

rburing gravatar imagerburing ( 2025-07-05 11:19:31 +0200 )edit

Many thanks! I'll do.

c.p. gravatar imagec.p. ( 2025-07-06 08:55:15 +0200 )edit