Aan de slagGa gratis aan de slag

90 and 95% bands

You are looking at a 40-day rolling average of the NO2 pollution levels for the city of Cincinnati in 2013. To provide as detailed a picture of the uncertainty in the trend you want to look at both the 90 and 99% intervals around this rolling estimate.

To do this, set up your two interval sizes and an orange ordinal color palette. Additionally, to enable precise readings of the bands, make them semi-transparent, so the Seaborn background grids show through.

Deze oefening maakt deel uit van de cursus

Improving Your Data Visualizations in Python

Cursus bekijken

Oefeninstructies

  • Set the opacity of the intervals to 40%.
  • Calculate the lower and upper confidence bounds.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

int_widths = ['90%', '99%']
z_scores = [1.67, 2.58]
colors = ['#fc8d59', '#fee08b']

for percent, Z, color in zip(int_widths, z_scores, colors):
    
    # Pass lower and upper confidence bounds and lower opacity
    plt.fill_between(
        x = cinci_13_no2.day, alpha = ____, color = color,
        y1 = cinci_13_no2['mean'] ____ ____*cinci_13_no2['std_err'],
        y2 = cinci_13_no2['mean'] ____ ____*cinci_13_no2['std_err'],
        label = percent)
    
plt.legend()
plt.show()
Code bewerken en uitvoeren