Using band thickness instead of coloring
You are a researcher investigating the elevation a rocket reaches before visual is lost and pollutant levels at Vandenberg Air Force Base. You've built a model to predict this relationship (stored in the DataFrame rocket_height_model), and since you are working independently, you don't have the money to pay for color figures in your journal article. You need to make your model results plot work in black and white. To do this, you will plot the 90, 95, and 99% intervals of the effect of each pollutant as successively smaller bars.
Deze oefening maakt deel uit van de cursus
Improving Your Data Visualizations in Python
Oefeninstructies
- Use a thickness of
15for 90%,10for 95%, and5for 99% interval lines. - Pass the interval thickness value to
plt.hlines(). - Set the interval color to
'gray'to lighten contrast.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Decrase interval thickness as interval widens
sizes = [ ____, ____, ____]
int_widths = ['90% CI', '95%', '99%']
z_scores = [ 1.67, 1.96, 2.58]
for percent, Z, size in zip(int_widths, z_scores, sizes):
plt.hlines(y = rocket_model.pollutant,
xmin = rocket_model['est'] - Z*rocket_model['std_err'],
xmax = rocket_model['est'] + Z*rocket_model['std_err'],
label = percent,
# Resize lines and color them gray
linewidth = ____,
color = '____')
# Add point estimate
plt.plot('est', 'pollutant', 'wo', data = rocket_model, label = 'Point Estimate')
plt.legend(loc = 'center left', bbox_to_anchor = (1, 0.5))
plt.show()