0
0
Matplotlibdata~15 mins

Figure size and DPI in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Figure size and DPI
📖 Scenario: You are preparing a simple plot to show sales data for a small shop. You want to control how big the plot looks and how clear it is by setting the figure size and DPI (dots per inch).
🎯 Goal: Create a matplotlib plot with a specific figure size and DPI, then display it.
📋 What You'll Learn
Create a figure with size 6 inches wide and 4 inches tall
Set the DPI of the figure to 100
Plot a simple line graph of sales data
Display the plot
💡 Why This Matters
🌍 Real World
Setting figure size and DPI helps make charts clear and well-sized for reports, presentations, or websites.
💼 Career
Data scientists and analysts often adjust figure size and DPI to create professional and readable visualizations.
Progress0 / 4 steps
1
Create sales data
Create a list called sales with these exact values: [10, 15, 7, 12, 20].
Matplotlib
Need a hint?

Use square brackets to create a list and separate numbers with commas.

2
Set figure size and DPI
Import matplotlib.pyplot as plt. Then create a figure with size 6 by 4 inches and DPI 100 using plt.figure(figsize=(6, 4), dpi=100) and save it in a variable called fig.
Matplotlib
Need a hint?

Use import matplotlib.pyplot as plt to import. Then use plt.figure() with figsize and dpi arguments.

3
Plot the sales data
Use plt.plot(sales) to create a line plot of the sales list.
Matplotlib
Need a hint?

Use plt.plot() and pass the sales list as argument.

4
Display the plot
Use plt.show() to display the plot on the screen.
Matplotlib
Need a hint?

Use plt.show() to open the plot window.