0
0
Matplotlibdata~30 mins

Line colors and width in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Line colors and width
📖 Scenario: You are working on a simple data visualization project. You want to draw lines on a graph with different colors and thicknesses to make the chart easy to understand.
🎯 Goal: Create a line plot with three lines. Each line should have a specific color and line width as given.
📋 What You'll Learn
Create three lists of y-values for three lines
Create a variable for the x-values
Plot each line with a specific color and line width
Display the plot
💡 Why This Matters
🌍 Real World
Line colors and widths help make charts clearer and easier to read in reports, presentations, and dashboards.
💼 Career
Data scientists and analysts use line styling to highlight important trends and differences in data visualizations.
Progress0 / 4 steps
1
Create data for the lines
Create a list called x with values [1, 2, 3, 4, 5]. Create three lists called y1, y2, and y3 with values [1, 4, 9, 16, 25], [2, 3, 5, 7, 11], and [5, 7, 6, 8, 7] respectively.
Matplotlib
Need a hint?

Use square brackets to create lists with the exact numbers given.

2
Import matplotlib and set up the plot
Import matplotlib.pyplot as plt. Create a variable called fig, ax by calling plt.subplots().
Matplotlib
Need a hint?

Use import matplotlib.pyplot as plt and plt.subplots() to prepare the plot.

3
Plot the lines with colors and widths
Use ax.plot() to plot the three lines with x and y1, y2, y3. Set the line colors to 'red', 'green', and 'blue' respectively. Set the line widths to 2, 4, and 6 respectively.
Matplotlib
Need a hint?

Use color='colorname' and linewidth=number inside ax.plot().

4
Display the plot
Use plt.show() to display the plot with the three colored lines of different widths.
Matplotlib
Need a hint?

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