Stacked Bar graph of unequal data

How can I plot a stacked bar graph for an unequal data set?
I tried, and it is plotting only an equal number (minimum) of values on y.

My data looks like this -

import plotly.graph_objects as go

forx = [1,2,3,4,5]
fory = [[4,6,8], [2,9], [5], [3,1,5,2], [6,8]]

data = []

for idx, i in enumerate(forx):
          data.append(go.Bar(name=str(i), x=forx, y=fory[idx]))


Hi @Statister welcome to the community!

Try filling your lists with None or 0 so that all have the same length.


I had tried filling/padding 0s, It didnโ€™t solve my problem.

The issues seem to be because of x axis position is selecting respecting index on y axis arrays and stacking them up.
x axis 0 picks all elements of 0 from all y axis arrays. i.e 1 on x axis will pick 4,2,5,3,6 from y axis arrays.

How do I make it stack all elements of a whole array, instead of individual elements of position from different arrays?
i.e x axis 1 to stacks y axis array [4,6,8]

Well, just padding will not work as you noticed. You will have to insert 0/None at the Y-indices where you donโ€™t have values vor the X-axis index.

How can I stack an entire array on x rather than multiple elements from arrays?