Density plots
In practice, histograms can be a substandard method for assessing the distribution of your data because they can be strongly affected by the number of bins that have been specified. Instead, kernel density plots represent a more effective way to view the distribution of your data. An example of how to generate a density plot of is shown below:
ax = df.plot(kind='density', linewidth=2)
The standard .plot() method is specified with the kind argument set to 'density'. We also specified an additional parameter linewidth, which controls the width of the line to be plotted.
Este ejercicio forma parte del curso
Visualizing Time Series Data in Python
Instrucciones del ejercicio
- Using the
co2_levelsDataFrame, produce a density plot of the CO2 level data with line width parameter of 4. - Annotate the x-axis labels of your boxplot with the string
'CO2'. - Annotate the y-axis labels of your boxplot with the string
'Density plot of CO2 levels in Maui Hawaii'.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# Display density plot of CO2 levels values
ax = ____.____(____=____, ____=____, fontsize=6)
# Annotate x-axis labels
____.____('CO2', fontsize=10)
# Annotate y-axis labels
____.____('Density plot of CO2 levels in Maui Hawaii', fontsize=10)
plt.show()