ComeçarComece de graça

Enhancing legibility

You and your colleagues have decided that the most important aspect of the data you want to show is the differences between the most "market-friendly" state, Vermont, and the least, Texas. To do this, put two plots side by side – a barplot showing the number of people per farmer's market in the state and a scatter plot showing the population on the x-axis and the number of markets on the y-axis.

Emphasize your findings by calling out Vermont and Texas by assigning them distinct colors. Also, provide a large and easy to read annotation for Texas.

Supplied is a vector state_colors that assigns Vermont and Texas unique colors and all other states gray along with the annotation describing Texas, tx_message.

Este exercício faz parte do curso

Improving Your Data Visualizations in Python

Ver curso

Instruções do exercício

  • Map the supplied color vector state_colors to the bar plot (ax1) with the palette argument in sns.barplot().
  • Map the color vector to the scatter plot points with the c argument.
  • Make sure annotation text is legible by changing its size to 15.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Draw barplot w/ colors mapped to state_colors vector
sns.barplot('people_per_market', 'state', ____ = ____,
            data = markets_by_state, ax = ax1)

# Map state colors vector to the scatterplot as well
p = sns.scatterplot('population', 'num_markets', c = ____,
                    data = markets_by_state, s = 60, ax = ax2)

# Log the x and y scales of our scatter plot so it's easier to read
ax2.set(xscale = "____", yscale = '____')

# Increase annotation text size for legibility
ax2.annotate(tx_message, xy = (26956958,230), 
             xytext = (26956958, 450),ha = 'right', 
             size = ____, backgroundcolor = 'white',
             arrowprops = {'facecolor':'black', 'width': 3})
sns.set_style('whitegrid')
plt.show()
Editar e executar o código