Digging in with basic transforms
You are curious to see if the population of a state correlates to the number of items sold at farmer's markets. To check this, take the log of the population and draw a scatter plot against the number of items sold by a market. From your previous explorations of the dataset, you know there will be a lot of overlap, so to get a better handle on the patterns you want to reduce the marker opacity.
This exercise is part of the course
Improving Your Data Visualizations in Python
Exercise instructions
- Use
numpy
(imported asnp
) to create a new column:log_pop
by taking the log of the state population. - Pass this newly created logged column to the scatter plot function's x-mapping.
- Set the scatter plot's opacity to 25% to show overlap.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create a new logged population column
markets['____'] = np.____(markets['____'])
# Draw a scatterplot of log-population to # of items sold
sns.scatterplot(x = '____',
y = 'num_items_sold',
# Reduce point opacity to show overlap
____ = ____,
data = markets)
plt.show()