Percentage stacked bar chart - error = “TypeError: only size-1 arrays can be converted to Python scalars” - why x & y values are not recognized? [closed]

datascience.stackexchange https://datascience.stackexchange.com/questions/46425

  •  01-11-2019
  •  | 
  •  

Question

enter image description here

df = pd.DataFrame(raw_data)
raw_data = {'X':[x1,x2,x3], 'Y':[y1,y2,y3]}
r =np.arange(len(df))

totals = [n+m for n,m in zip(df['X'], df['Y'])]
X = [n / m * 100 for n,m in zip(df['X'], totals)]
Y = [n / m * 100 for n,m in zip(df['Y'], totals)]

barWidth = 0.8
names = ("R 1","R 2","R 3")

plt.bar(r, X, color='r', edgecolor='black', width=barWidth,label="X")

plt.bar(r, Y, bottom=X, color='c', edgecolor='black', width=barWidth,label="Y")


plt.title("TEST - Stacked bar graph (%)",y=1.05,fontsize=20)
plt.xticks(r, names)
plt.xlabel("Vrsta obrazovanja",fontsize=15)
plt.ylabel("Precentage %",fontsize=15) 
plt.legend(loc="lower center")

plt.show()

enter image description here

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with datascience.stackexchange
scroll top