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

How to draw bars that are going from -60 up to zero?


usually bars start from zero and go down in case of negative value, and up in case of positive value.

But, I have a requirement for bar charts that always start from -60 and go to any value above up to zereo, something like this:


How to plot it with plotly (I am using python, but any advice will be helpful) in the most elegant way?

For now, I have multiplied all values by -1 (changed sign, make all values as positive) and plot them as usual from zero up. Now I am trying to find a way to change y-axis labels to simulate range -60 to 0.
Maybe there is a better approach.

Does someone have an idea?


Hi @gluperegistracije you can use the base attribute of go.Bar for this:

Hi Emmanuelle,

according to you suggestion, I have two graphs.

that are presenting the same dataframe (at the picture bellow dataframe is in wide format in order to be more clear, but in examples above uses long format):

Bars in the top graph should be upside down, but each bar should start at -60.
The Eight bar should start at -60 and end up at zero.

I tried base as you have suggested but than I got second graph which is still not what I need.

Can you please help?


I also tried to make all dataframe values positive, and set all tap8 values to (positive) 60.
Than I tried the same approach, but only the first bar respects base (but it has its second representation above itself).

Still not good. :smirk:

I finally got it with

fig.update_traces(base = [-60]*24 * len(df))

1 Like