Separating a lot of bands
It is relatively simple to plot a bunch of trend lines on top of each other for rapid and precise comparisons. Unfortunately, if you need to add uncertainty bands around those lines, the plot becomes very difficult to read. Figuring out whether a line corresponds to the top of one class' band or the bottom of another's can be hard due to band overlap. Luckily in Seaborn, it's not difficult to break up the overlapping bands into separate faceted plots.
To see this, explore trends in SO2 levels for a few cities in the eastern half of the US. If you plot the trends and their confidence bands on a single plot - it's a mess. To fix, use Seaborn's FacetGrid()
function to spread out the confidence intervals to multiple panes to ease your inspection.
Este ejercicio forma parte del curso
Improving Your Data Visualizations in Python
Instrucciones del ejercicio
- Set up a facet grid to separate the plots by the
city
column ineastern_SO2
. - Send the confidence interval plotting function to
map()
. - Color the confidence intervals
'coral'
. - Help the overlaid mean line drawn with
g.map(plt.plot,...)
stand out against the confidence bands by coloring it white.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# Setup a grid of plots with columns divided by location
g = sns.FacetGrid(eastern_SO2, col = '____', col_wrap = 2)
# Map interval plots to each cities data with corol colored ribbons
g.map(plt.____, 'day', 'lower', 'upper', ____ = 'coral')
# Map overlaid mean plots with white line
g.map(plt.plot, 'day', 'mean', ____ = '____')
plt.show()