0
0
Matplotlibdata~30 mins

Tick marks and tick labels in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Tick marks and tick labels
📖 Scenario: You are creating a simple line chart to show the sales of a small shop over 5 days. You want to control the tick marks and labels on the x-axis to make the chart easy to read.
🎯 Goal: Build a matplotlib line chart with custom tick marks and tick labels on the x-axis.
📋 What You'll Learn
Create a list of sales numbers for 5 days.
Create a list of day names for the x-axis labels.
Plot the sales data as a line chart.
Set the x-axis tick marks to match the days.
Set the x-axis tick labels to the day names.
💡 Why This Matters
🌍 Real World
Customizing tick marks and labels helps make charts clearer and easier to understand in reports and presentations.
💼 Career
Data analysts and scientists often need to control chart details like tick marks to communicate data effectively.
Progress0 / 4 steps
1
Create sales data and day names
Create a list called sales with these values: 10, 15, 7, 12, 9. Create a list called days with these values: 'Mon', 'Tue', 'Wed', 'Thu', 'Fri'.
Matplotlib
Need a hint?

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

2
Import matplotlib and prepare the plot
Import matplotlib.pyplot as plt. Use plt.figure() to create a new figure.
Matplotlib
Need a hint?

Use import matplotlib.pyplot as plt to import. Then call plt.figure() to start a new plot.

3
Plot sales and set x-axis ticks and labels
Use plt.plot(sales) to plot the sales data. Use plt.xticks() to set the tick marks at positions 0, 1, 2, 3, 4 and the tick labels to the days list.
Matplotlib
Need a hint?

Use plt.plot(sales) to draw the line. Use plt.xticks() with two arguments: a list of positions and a list of labels.

4
Display the plot
Use plt.show() to display the plot with the custom tick marks and labels.
Matplotlib
Need a hint?

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