Aan de slagGa gratis aan de slag

Stacking to find trends

In the farmers market dataset, you are interested in the number of months that a market stays open in relation to its geography, more specifically its longitude. You're curious to see if there are any regions of the country that behave noticeably different from the others.

To do this, you create a basic map with a scatter plot of the latitude and longitude of each market, coloring each market by the number of months it's open. Further digging into the latitude relationship, you draw a regression plot of the latitude to the number of months open with a flexible fit line to determine if any trends appear. You want to view these simultaneously to get the clearest picture of the trends.

Deze oefening maakt deel uit van de cursus

Improving Your Data Visualizations in Python

Cursus bekijken

Oefeninstructies

  • Set up plt.subplots() to have two vertically stacked plots.
  • Assign the first (top) plot to the lon, lat scatter plot.
  • Assign the second (bottom) plot to the lon to months_open regression plot.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Setup two stacked plots
_, (ax1, ax2) = plt.subplots(____, ____)

# Draw location scatter plot on first plot
sns.scatterplot("lon", "lat", 'months_open', 
                palette = sns.light_palette("orangered",n_colors = 12), 
                legend = False, data = markets,
                ax = ____);

# Plot a regression plot on second plot
sns.regplot('lon', 'months_open',
            scatter_kws = {'alpha': 0.2, 'color': 'gray', 'marker': '|'},
            lowess = True,
            marker = '|', data = markets, 
            ax = ____)

plt.show()
Code bewerken en uitvoeren