0
0
Matplotlibdata~30 mins

Colorblind-friendly palettes in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Colorblind-friendly palettes
📖 Scenario: You are working on a data visualization project. You want to make sure your charts are easy to understand for everyone, including people who are colorblind. Using colorblind-friendly palettes helps make your visuals clear and accessible.
🎯 Goal: Create a simple bar chart using a colorblind-friendly palette from matplotlib. You will first set up the data, then choose the palette, apply it to the bars, and finally display the chart.
📋 What You'll Learn
Create a dictionary called fruits with these exact entries: 'Apples': 10, 'Bananas': 15, 'Cherries': 7, 'Dates': 12
Create a variable called palette and set it to the colorblind-friendly palette 'tab10' from matplotlib
Use a for loop with variables fruit, count to iterate over fruits.items() and plot bars with colors from palette
Use plt.show() to display the bar chart
💡 Why This Matters
🌍 Real World
Colorblind-friendly palettes help make charts readable for people with color vision differences, improving accessibility in reports and presentations.
💼 Career
Data scientists and analysts must create visuals that communicate clearly to all audiences, including those with colorblindness.
Progress0 / 4 steps
1
DATA SETUP: Create the fruit count dictionary
Create a dictionary called fruits with these exact entries: 'Apples': 10, 'Bananas': 15, 'Cherries': 7, 'Dates': 12.
Matplotlib
Need a hint?

Use curly braces {} to create the dictionary with the exact fruit names and counts.

2
CONFIGURATION: Set the colorblind-friendly palette
Import matplotlib.pyplot as plt. Then create a variable called palette and set it to the colorblind-friendly palette 'tab10' from matplotlib.
Matplotlib
Need a hint?

Use plt.get_cmap('tab10') to get the colorblind-friendly palette.

3
CORE LOGIC: Plot bars using the colorblind-friendly palette
Use a for loop with variables fruit and count to iterate over fruits.items(). Plot bars with plt.bar() using colors from palette by indexing with the loop index.
Matplotlib
Need a hint?

Use enumerate(fruits.items()) to get the index i and the fruit and count. Use palette(i / (len(fruits) - 1)) for the bar color.

4
OUTPUT: Display the bar chart
Use plt.show() to display the bar chart with the colorblind-friendly palette applied.
Matplotlib
Need a hint?

Call plt.show() to open the window with the bar chart.