2
votes

I will make a stacked bar chart in matplotlib. Somehow it doesnt include all the bar chart that i gave him (there should be like 50 bar charts stacked on each other)

The code:

N=45 #numbers of columns
max_el=50
ind=np.arrange(N)
for bar in range(0,max_el):
   y=[dic[value][bar] for value in dic]
   plt.bar(ind,y,)
plt.show()

note: I used the similar code and same data and made a stacked bar chart with plotly (which worked)

With plotly how it should look like

With matplotlib how it looks like

Some of the values of variables are zeros or 0.1. Could that be the problem ?

1
You are not stacking the bars. Refer to the stacked bar graph example on how to create stacked bars.ImportanceOfBeingErnest
@ImportanceOfBeingErnest what am i doing wrong ? I cant type all the data maunally, i need to use dics and loopsNikola Vinko
oh i got it.... with plotly was so much nicer. Now i have to calculate for each graph the "bottom"Nikola Vinko

1 Answers

1
votes

As described in the comments, you need to add a bottoms array that keeps track of how much each should be moved up from the 0 line. Otherwise, they all start plotting a 0 and overplot one another, with the tallest one sticking up to its values and each one hiding those that were plotted before.