0
0
Matplotlibdata~30 mins

Font properties customization in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Font properties customization
📖 Scenario: Imagine you are creating a simple chart to show sales data for a small shop. You want to make the chart easy to read by changing the font style and size of the title and labels.
🎯 Goal: You will create a bar chart and customize the font properties of the title and axis labels using matplotlib.
📋 What You'll Learn
Create a bar chart with sales data
Customize the font size and font family of the chart title
Customize the font size and font style of the x-axis and y-axis labels
Display the chart with the customized fonts
💡 Why This Matters
🌍 Real World
Customizing font properties helps make charts clearer and more attractive for reports and presentations.
💼 Career
Data scientists and analysts often need to create visualizations that communicate data effectively, including styling text for readability.
Progress0 / 4 steps
1
Create sales data dictionary
Create a dictionary called sales with these exact entries: 'Apples': 30, 'Bananas': 45, 'Cherries': 15, 'Dates': 10.
Matplotlib
Need a hint?

Use curly braces {} to create a dictionary with keys as fruit names and values as sales numbers.

2
Set font properties for title and labels
Create two variables: title_font as a dictionary with 'fontsize' set to 16 and 'fontfamily' set to 'serif', and label_font as a dictionary with 'fontsize' set to 12 and 'fontstyle' set to 'italic'.
Matplotlib
Need a hint?

Use dictionaries to store font properties like fontsize, fontfamily, and fontstyle.

3
Create bar chart with customized fonts
Import matplotlib.pyplot as plt. Use plt.bar() to create a bar chart from sales.keys() and sales.values(). Use plt.title() with text 'Fruit Sales' and font properties from title_font. Use plt.xlabel() with text 'Fruit' and font properties from label_font. Use plt.ylabel() with text 'Quantity' and font properties from label_font.
Matplotlib
Need a hint?

Use fontdict parameter in plt.title(), plt.xlabel(), and plt.ylabel() to apply font properties.

4
Display the chart
Use plt.show() to display the bar chart with the customized font properties.
Matplotlib
Need a hint?

Call plt.show() to open a window showing the chart.