Black Lives Matter. Please consider donating to Black Girls Code today.

Bar graph does not have uniform widths with logarithmic axes


I have a bar graph with a logarithmic x axis in order to see a lot of data in the x direction. However, when I have that combo it creates a graph where the bar width varies. See in my example the the bars on the left is wider then those on the right. Is there a way to make the width size consistent?


I know this is an old question, but I just encountered this for myself and was surprised and annoyed at first. However, it actually makes some sense in terms of preventing bins from overlapping. I found that by passing a computed width array it wasn’t too hard to compensate for this variable width and get constant widths.

const x = [0.0001, 0.1, 1, 2, 5, 10];
const trace1 = {
    x: x,
    y:, i) => 2*(i+1)-x),
    width: => x/2); // <--- make width proportional to x
    type: 'bar'