0
0
Matplotlibdata~15 mins

Zoom and pan with toolbar in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Zoom and Pan with Toolbar in Matplotlib
📖 Scenario: You are analyzing sales data over a week. You want to create a simple line chart to see the sales trend. Later, you want to explore the chart by zooming in and panning around using the toolbar.
🎯 Goal: Create a line plot of sales data using matplotlib. Then enable the interactive toolbar so you can zoom and pan the plot to explore the data.
📋 What You'll Learn
Create a list called days with the values: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
Create a list called sales with the values: [150, 200, 170, 240, 300, 280, 320]
Import matplotlib.pyplot as plt
Create a line plot with days on the x-axis and sales on the y-axis
Enable the interactive toolbar for zoom and pan
Show the plot
💡 Why This Matters
🌍 Real World
Data scientists and analysts often need to explore data visually. Zooming and panning help to focus on specific parts of the data for better understanding.
💼 Career
Knowing how to create interactive plots with zoom and pan is useful for data visualization tasks in many data science and analytics jobs.
Progress0 / 4 steps
1
Create the sales data lists
Create a list called days with the values ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']. Then create a list called sales with the values [150, 200, 170, 240, 300, 280, 320].
Matplotlib
Need a hint?

Use square brackets to create lists. Separate items with commas.

2
Import matplotlib.pyplot as plt
Import matplotlib.pyplot as plt to prepare for plotting.
Matplotlib
Need a hint?

Use the import keyword followed by the module name and as plt.

3
Create the line plot and enable toolbar
Use plt.plot(days, sales) to create a line plot. Then call plt.show() to display the plot with the interactive toolbar enabled for zoom and pan.
Matplotlib
Need a hint?

Use plt.plot() with the two lists as arguments. Then call plt.show() to open the plot window.

4
Display the plot with zoom and pan toolbar
Run the program to display the plot window. Use the toolbar buttons to zoom in and pan around the sales data.
Matplotlib
Need a hint?

After running, a window with the plot and toolbar should appear. Use the magnifying glass icon to zoom and the hand icon to pan.