Beyond 95%

Improving Your Data Visualizations in Python

Nick Strayer

Instructor

Solid single-level confidence band on top with arrow pointing to three-tiered band beneath

Improving Your Data Visualizations in Python

Solid single-level confidence band on top with arrow pointing to three-tiered band beneath and arrow pointing to 90% level of lower band

Improving Your Data Visualizations in Python

Solid single-level confidence band on top with arrow pointing to three-tiered band beneath and arrow pointing to 95% level of lower band

Improving Your Data Visualizations in Python

Solid single-level confidence band on top with arrow pointing to three-tiered band beneath and arrow pointing to 99% level of lower band

Improving Your Data Visualizations in Python

Solid single-level confidence band on top with arrow pointing to three-tiered band beneath

Improving Your Data Visualizations in Python
# Interval size setup
sizes    = ['99%', '95%', '90%']
Z_scores = [2.58,   1.96,  1.67]
colors   = ['#fee0b6','#f1a340', '#b35806']


for size, z, color in zip(sizes, Z_scores, colors): plt.hlines(y = data.y, # Calculate lower and upper boundaries xmin = data['est'] - z*data['std_err'], xmax = data['est'] + z*data['std_err'], # Color by interval size color = color,
# Make line thicker for visibility linewidth = 7,
# Label line so legend text is clear label = size)
plt.plot('est', 'y', 'ko', data = data, label = 'Point Estimate') plt.legend()
Improving Your Data Visualizations in Python

Three horizontal confidence bands with colors indicating the 90, 95, and 99% confidence intervals

Improving Your Data Visualizations in Python

Three confidence intervals with the top using darker colors for outside intervals, the middle one using very similar shades, and the final one using darker colors for inside intervals

Improving Your Data Visualizations in Python
widths   = [    '99%',     '90%']
z_scores = [     2.58,      1.67]
colors   = ['#99d8c9', '#41ae76']

for percent, Z, color in zip(widths, z_scores, colors):
    # Set color to distinquish bands
    plt.fill_between(
        x=data.day, 
        y1=data['mean'] - Z*data['std_err'],
        y2=data['mean'] + Z*data['std_err']
        color=color,

# Lower opacity so grid can show through alpha=0.5,
# Give each band id for the legend label=percent)
Improving Your Data Visualizations in Python

Two confidence bands overlaid with the smaller darker band inlaid within, the larger and lighter band

Improving Your Data Visualizations in Python
sizes = ['99% Confidence Interval', '95%', '90%']

# Set up different line widths for intervals
widths   = [   5,     10,    15]
Z_scores = [2.58,   1.96,  1.67]

for size, z, width in zip(sizes, Z_scores, widths):
    plt.hlines(
        y = data.y, label = size,
        xmin = data['est'] - z*data['std_err'], 
        xmax = data['est'] + z*data['std_err'], 
        color = 'grey'

# Adjust line thickness by interval linewidth = width)
plt.plot('est', 'y', 'wo', data = data, label = 'Point Estimate') plt.legend()
Improving Your Data Visualizations in Python

Three three level confidence intervals with the inner intervals occupying the thickest band and decreasing in band thickness as intervals go outward

Improving Your Data Visualizations in Python

Let's expand our boundaries!

Improving Your Data Visualizations in Python

Preparing Video For Download...