LoslegenKostenlos loslegen

Fixing Seaborn's bar charts

Seaborn's default values for the colors of bars in a bar chart are not ideal for the most accurate perception. By drawing each bar as a different color, there is a risk of the viewer seeing two identical sized bars as different sizes as people tend to see some colors as 'larger' than others.

Basic rainbow colored bar plot

We discussed two easy ways to fix this. First, to put a border around the bars; second, change all bar colors to the same value. Try both of these solutions on our pollution data.

Diese Übung ist Teil des Kurses

Improving Your Data Visualizations in Python

Kurs anzeigen

Interaktive Übung

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

import numpy as np

sns.barplot(y = 'city', x = 'CO', 
            estimator = np.mean,
            ci = False,
            data = pollution,
            # Add a border to the bars
            ____ = ____)
plt.show()
Code bearbeiten und ausführen