Visualizing international income distribution
seaborn
is a Python visualization library for statistical data visualization based on matplotlib
.
By default, the distplot()
function in the seaborn
package creates a histogram, where data is grouped into ranges and and plotted as bars, and fits a kernel density estimation (KDE), or smoothed histogram. You can also use distplot()
to create another kind of graph called a rugplot, which adds markers at the bottom of the chart to indicate the density of observations along the x axis.
seaborn.distplot(a, bins=None, hist=True, kde=True, rug=False, ...)
In previous exercises, you created a quantile plot which provided a fairly granular sense of the level of income per capita at different points of the distribution. Here, you will use distplot()
to get the full picture!
pandas
has been imported as pd
, and the income
DataFrame from the previous exercise is available in your workspace.
This exercise is part of the course
Importing and Managing Financial Data in Python
Exercise instructions
- Import
seaborn
assns
andmatplotlib.pyplot
asplt
. - Print the summary statistics provided by
.describe()
. - Plot and show a basic histogram of the
'Income per Capita'
column with.distplot()
. - Create and show a rugplot of the same data by setting the additional arguments
bins
equal to 50,kde
toFalse
, andrug
toTrue
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import seaborn and matplotlib
____
____
# Print the summary statistics for income
print(____.____())
# Plot a basic histogram of income per capita
____
# Show the plot
plt.show()
# Plot a rugplot
sns.distplot(income['Income per Capita'], ____, ____, ____)
# Show the plot
plt.show()