0
0
Matplotlibdata~15 mins

Grid lines configuration in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Grid lines configuration
📖 Scenario: You are creating a simple line chart to show sales over a week. You want to make the chart easier to read by adding grid lines.
🎯 Goal: Build a line chart using matplotlib with grid lines enabled and customized.
📋 What You'll Learn
Create a list called days with the days of the week as strings.
Create a list called sales with sales numbers for each day.
Create a variable called grid_style to set the style of grid lines.
Plot the sales data using plt.plot().
Enable grid lines using plt.grid() with the style from grid_style.
Print the plot with grid lines visible.
💡 Why This Matters
🌍 Real World
Grid lines help people read charts more easily by showing reference lines behind the data points.
💼 Career
Data scientists and analysts often customize plots to make data clearer and more professional for reports and presentations.
Progress0 / 4 steps
1
Create sales data lists
Create a list called days with these exact values: 'Mon', 'Tue', 'Wed', 'Thu', 'Fri'. Create another list called sales with these exact values: 150, 200, 170, 220, 180.
Matplotlib
Need a hint?

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

2
Set grid line style
Create a variable called grid_style and set it to the string '--' to represent dashed grid lines.
Matplotlib
Need a hint?

Assign the string '--' to the variable grid_style.

3
Plot sales and enable grid lines
Import matplotlib.pyplot as plt. Use plt.plot() with days and sales to create the line chart. Then enable grid lines using plt.grid() with the argument linestyle=grid_style.
Matplotlib
Need a hint?

Use import matplotlib.pyplot as plt to import. Use plt.plot() to plot. Use plt.grid(linestyle=grid_style) to add grid lines.

4
Display the plot
Use plt.show() to display the plot with the grid lines.
Matplotlib
Need a hint?

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