Reputation: 51
How to make histogram-style bar-plot of continuous data in python?
The data I have looks like this with simple plt.plot(x,y) (x-axis is not normalized, but is real data from 0 to 1):
So obviously I would need to plot some kind of distribution, but I don't know what is it called that I am looking for. I want the x and y axis to stay the same, so I don't want to plot histogram of one of the variables, but instead of plotting every point, I want to plot only the average values of y between some intervals of x. I could do this with plt.bar(bins, y-columns), and I know how to calculate the bins, but how to find automatically the corresponding y-column values?
I suppose there must be an easy and automated way of doing what I described, however, I can't find it.
Upvotes: 1
Views: 24312
Reputation: 79
Might this tutorial may help you,
https://cmdlinetips.com/2019/02/how-to-make-histogram-in-python-with-pandas-and-seaborn/
sns.distplot(df['lifeExp'], kde=False, label='Africa')
df =gapminder[gapminder.continent == 'Americas']
sns.distplot(df['lifeExp'], kde=False,label='Americas')
# Plot formatting
plt.legend(prop={'size': 12})
plt.title('Life Expectancy of Two Continents')
plt.xlabel('Life Exp (years)')
plt.ylabel('Density')
Result as:
Upvotes: 3