Cleaning up bands for overlaps
You are working for the city of Denver, Colorado and want to run an ad campaign about how much cleaner Denver's air is than Long Beach, California's air. To investigate this claim, you will compare the SO2 levels of both cities for the year 2014 (provided as the DataFrame SO2_compare
). Since you are solely interested in how the cities compare, you want to keep the bands on the same plot. To make the bands easier to compare, decrease the opacity of the confidence bands and set a clear legend.
This exercise is part of the course
Improving Your Data Visualizations in Python
Exercise instructions
- Filter the
SO2_compare
to thefor
loop's currently selectedcity
. - Color both the intervals and mean lines with the
color
accompanying eachcity
. - Lower the interval and mean line opacities to 0.4 and 0.25, respectively.
- Override the default legend labels in
plt.plot()
by setting thelabel
argument to the city name.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
for city, color in [('Denver',"#66c2a5"), ('Long Beach', "#fc8d62")]:
# Filter data to desired city
city_data = SO2_compare[SO2_compare.____ == ____]
# Set city interval color to desired and lower opacity
plt.fill_between(x = 'day', y1 = 'lower', y2 = 'upper', data = city_data,
color = ____, alpha = ____)
# Draw a faint mean line for reference and give a label for legend
plt.plot('day','mean', data = city_data, ____ = city,
color = ____, alpha = ____)
plt.legend()
plt.show()