'Histogram multiple columns, percentage per columns same plot
I have this dataframe(df_histo):
ID SA WE EE
1 NaN 320 23.4
2 234 2.3 NaN
.. .. .. ..
345 1.2 NaN 234
I can plot a correct histogram if I use density=True,
buckets = [0,250,500,1000,1500,2000,2500,3000,3500,4000,4500,5000]
plt.hist(df_histo, bins=buckets, label=dfltabv_histo.columns, density=True)
however I want to visualize the data(1 histogram) in total percentages for each country. That is, what percentage each bins represents in that country
the closest attempt has been this(with individual columns it works):
plt.hist(dfltabv_histo, bins=buckets, label=dfltabv_histo.columns, weights=np.ones(len(dfltabv_histo)) / len(dfltabv_histo))
plt.gca().yaxis.set_major_formatter(PercentFormatter(1))
ValueError: weights should have the same shape as x
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
