Percentuale grafico a barre imbottito - Errore = "TypeEerror: solo array di dimensioni -1 possono essere convertiti in scalari di Python" - Perché i valori X & Y non sono riconosciuti? [Chiuso

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

  •  01-11-2019
  •  | 
  •  

Domanda

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

Nessuna soluzione corretta

Autorizzato sotto: CC-BY-SA insieme a attribuzione
scroll top