Axis limits (xlim, ylim)
📖 Scenario: You are analyzing the sales data of a small store over a week. You want to visualize the sales numbers clearly by setting the limits of the x-axis and y-axis on the graph.
🎯 Goal: Create a simple line plot of daily sales and set the x-axis limits to show only days 1 to 7 and the y-axis limits to show sales from 0 to 100.
📋 What You'll Learn
Create a list called
days with values from 1 to 7 representing days of the week.Create a list called
sales with the exact sales numbers: 20, 35, 30, 50, 70, 65, 80.Create two variables called
x_min and x_max with values 1 and 7 respectively.Create two variables called
y_min and y_max with values 0 and 100 respectively.Use
plt.plot(days, sales) to plot the sales data.Use
plt.xlim(x_min, x_max) and plt.ylim(y_min, y_max) to set the axis limits.Use
plt.show() to display the plot.💡 Why This Matters
🌍 Real World
Setting axis limits helps focus on important parts of data in graphs, making trends easier to see.
💼 Career
Data scientists and analysts often adjust axis limits to create clear and informative visualizations for reports and presentations.
Progress0 / 4 steps