Major and Minor Ticks in Matplotlib
📖 Scenario: You are creating a simple line chart to show the sales trend over 10 days. To make the chart easier to read, you want to add both major and minor ticks on the x-axis.
🎯 Goal: Build a matplotlib line plot with major ticks every 2 days and minor ticks every day on the x-axis.
📋 What You'll Learn
Create a list called
days with values from 1 to 10.Create a list called
sales with these exact values: 5, 7, 9, 6, 8, 10, 7, 9, 11, 8.Create a plot with
days on the x-axis and sales on the y-axis.Set major ticks on the x-axis at every 2 days using
MultipleLocator(2).Set minor ticks on the x-axis at every 1 day using
MultipleLocator(1).Display the plot.
💡 Why This Matters
🌍 Real World
In real life, clear charts with well-placed ticks help people understand data trends easily, like sales over time or temperature changes.
💼 Career
Data scientists and analysts often customize plots to make reports and dashboards more readable and professional.
Progress0 / 4 steps