Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Dashboard layout patterns
📖 Scenario: You work as a data analyst for a small company. Your manager wants a simple dashboard to see sales data and customer feedback side by side. You will create a dashboard layout using matplotlib to show two charts in one window.
🎯 Goal: Create a dashboard layout with two charts side by side using matplotlib. The first chart will show sales data as a bar chart. The second chart will show customer feedback scores as a line chart.
📋 What You'll Learn
Create a dictionary called sales_data with product names as keys and sales numbers as values
Create a list called feedback_scores with 5 numeric values representing customer feedback
Use matplotlib.pyplot.subplots() to create a figure with two side-by-side plots
Plot a bar chart of sales_data on the left subplot
Plot a line chart of feedback_scores on the right subplot
Add titles to each subplot: 'Sales Data' and 'Customer Feedback'
Display the dashboard using plt.show()
💡 Why This Matters
🌍 Real World
Dashboards are used in many companies to show important data clearly and quickly. This project shows how to arrange multiple charts in one window for easy comparison.
💼 Career
Data analysts and scientists often create dashboards to communicate insights to managers and teams. Knowing how to layout multiple charts is a key skill.
Progress0 / 4 steps
1
Create sales data dictionary
Create a dictionary called sales_data with these exact entries: 'Apples': 30, 'Bananas': 45, 'Cherries': 15, 'Dates': 10, 'Elderberries': 5.
Matplotlib
Hint
Use curly braces {} to create a dictionary. Separate keys and values with colons.
2
Create customer feedback scores list
Create a list called feedback_scores with these exact numeric values: 4, 5, 3, 4, 5.
Matplotlib
Hint
Use square brackets [] to create a list of numbers separated by commas.
3
Create dashboard layout with two subplots
Import matplotlib.pyplot as plt. Use plt.subplots() to create a figure and two side-by-side axes stored in variables fig and axes. Then plot a bar chart of sales_data on axes[0] and a line chart of feedback_scores on axes[1]. Add the titles 'Sales Data' and 'Customer Feedback' to the respective subplots.
Matplotlib
Hint
Use plt.subplots(1, 2) to create two plots side by side. Use axes[0].bar() for bar chart and axes[1].plot() for line chart. Use set_title() to add titles.
4
Display the dashboard
Add a line to display the dashboard window using plt.show().
Matplotlib
Hint
Use plt.show() to open the window with your dashboard charts.
Practice
(1/5)
1. What is the main purpose of using dashboard layout patterns in matplotlib?
easy
A. To organize multiple charts clearly for easy understanding
B. To change the color of charts automatically
C. To add animations to charts
D. To export charts as PDF files
Solution
Step 1: Understand dashboard layout purpose
Dashboard layouts help arrange multiple charts so viewers can understand data easily.
Step 2: Identify the correct purpose in options
Only To organize multiple charts clearly for easy understanding mentions organizing charts clearly, which matches the purpose.
Final Answer:
To organize multiple charts clearly for easy understanding -> Option A
Quick Check:
Dashboard layout = organize charts clearly [OK]
Hint: Dashboards arrange charts clearly for easy reading [OK]
Common Mistakes:
Confusing layout with color or animation features
Thinking layout changes export formats
Assuming layout adds interactivity automatically
2. Which of the following is the correct way to create a 2x2 grid of charts using matplotlib?
easy
A. plt.figure(2, 2)
B. plt.grid(2, 2)
C. plt.subplots(2, 2)
D. plt.plot(2, 2)
Solution
Step 1: Recall the function for grid layout
plt.subplots() creates a grid of subplots; parameters define rows and columns.
Step 2: Match correct syntax
plt.subplots(2, 2) creates a 2 by 2 grid; other options do not create grids.
Final Answer:
plt.subplots(2, 2) -> Option C
Quick Check:
Grid layout = plt.subplots(rows, cols) [OK]
Hint: Use plt.subplots(rows, cols) for grid layouts [OK]
Common Mistakes:
Using plt.grid() which controls gridlines, not layout
Confusing plt.figure() with subplot grid creation
Using plt.plot() which draws single charts only
3. What will be the output layout when running this code?
fig, axs = plt.subplots(1, 3)
for ax in axs:
ax.plot([1, 2, 3], [1, 4, 9])
plt.tight_layout()
plt.show()
medium
A. Three rows with one chart each stacked vertically
B. A single row with three side-by-side line charts
C. One chart only with three lines overlapping
D. An error because plt.tight_layout() is missing parameters
Solution
Step 1: Analyze plt.subplots(1, 3)
This creates 1 row and 3 columns, so three charts side by side.
Step 2: Understand the loop plotting
Each axis plots the same line chart, so three separate charts appear horizontally.
Final Answer:
A single row with three side-by-side line charts -> Option B
Quick Check:
1 row, 3 cols = 3 charts side by side [OK]
Hint: Rows x cols in plt.subplots defines chart grid shape [OK]
Common Mistakes:
Thinking 1,3 means 3 rows stacked vertically
Assuming all lines plot on one chart
Believing plt.tight_layout() causes errors without args
4. Identify the error in this code snippet for creating a 2x2 dashboard layout:
D. axs is an array; calling axs.plot() causes an error
Solution
Step 1: Understand axs type from plt.subplots(2, 2)
axs is a 2x2 array of axes, not a single axis object.
Step 2: Identify incorrect method call
Calling axs.plot() tries to call plot on the array, which causes an error; must call plot on individual axes.
Final Answer:
axs is an array; calling axs.plot() causes an error -> Option D
Quick Check:
Array of axes needs individual plot calls [OK]
Hint: Call plot on each axis, not on the axes array [OK]
Common Mistakes:
Calling plot on the whole axs array instead of elements
Thinking plt.subplots can't create 2x2 grids
Forgetting plt.show() needs parentheses
5. You want to create a dashboard with 3 charts: one large chart on the left and two smaller stacked charts on the right. Which matplotlib layout pattern best fits this requirement?
hard
A. Use GridSpec to create a 2-column layout with different row spans
B. Use plt.subplots(3, 1) for three stacked charts vertically
C. Use plt.subplots(1, 3) for three charts side by side equally sized
D. Use plt.subplot() three times with default sizes
Solution
Step 1: Understand layout needs
One large chart on left and two smaller stacked on right means uneven grid with row spans.
Step 2: Identify suitable layout tool
GridSpec allows flexible grid with different row/column spans, perfect for this layout.