Pourcentage du graphique à barres empilé - error = «TypeError: seuls les tableaux de taille 1 peuvent être convertis en scalaires Python» - Pourquoi les valeurs X & Y ne sont pas reconnues? [fermé
-
01-11-2019 - |
Question
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()
Pas de solution correcte
Licencié sous: CC-BY-SA avec attribution
Non affilié à datascience.stackexchange