LoslegenKostenlos loslegen

Hardcoding a highlight

You are working with the city of Houston to look at the relationship between sulfur dioxide (SO2) and nitrogen dioxide (NO2) pollution, specifically, pollution in the most recent year data was collected (2014). You have singled out a particularly bad day, November 26th, where there was a bad spike in the SO2 levels. To draw the viewers attention to this bad day, you will highlight it in a bright orangish-red and color the rest of the points gray.

pandas, matplotlib.pyplot, and seaborn are loaded as pd, plt, and sns, respectively, and will be available in your workspace for the rest of the course.

This course touches on a lot of concepts you may have forgotten, so if you ever need a quick refresher, download the Seaborn Cheat Sheet and keep it handy!

Diese Übung ist Teil des Kurses

Improving Your Data Visualizations in Python

Kurs anzeigen

Anleitung zur Übung

  • Modify the list comprehension to color the value corresponding to the 330th day (November 26th) of the year 2014 to orangered and the rest of the points to lightgray.
  • Pass the houston_colors array to regplot() using the scatter_kws argument to color the points.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

houston_pollution = pollution[pollution.city  ==  'Houston']

# Make array orangred for day 330 of year 2014, otherwise lightgray
houston_colors = ['orangered' if (____  ==  330) & (____  ==  2014) else 'lightgray' 
                  for day,year in zip(houston_pollution.____, houston_pollution.____)]

sns.regplot(x = 'NO2',
            y = 'SO2',
            data = houston_pollution,
            fit_reg = False, 
            # Send scatterplot argument to color points 
            scatter_kws = {'facecolors': ____, 'alpha': 0.7})
plt.show()
Code bearbeiten und ausführen