0
0
Matplotlibdata~30 mins

Why axis formatting matters in Matplotlib - See It in Action

Choose your learning style9 modes available
Why axis formatting matters
📖 Scenario: You are analyzing sales data for a small store. You want to create a simple line chart to show sales over days. Proper axis formatting will help make the chart clear and easy to understand.
🎯 Goal: Build a line chart using matplotlib that shows sales over days with clear axis labels and formatted ticks.
📋 What You'll Learn
Create a list called days with values 1 to 7 representing days of the week
Create a list called sales with exact values: 150, 200, 170, 220, 180, 210, 190
Create a matplotlib line plot using days and sales
Set the x-axis label to 'Day of Week'
Set the y-axis label to 'Sales ($)'
Format the y-axis ticks to show dollar sign and no decimals
Display the plot
💡 Why This Matters
🌍 Real World
Axis formatting helps make charts easy to read and understand in reports and presentations.
💼 Career
Data scientists and analysts use axis formatting to communicate data insights clearly to others.
Progress0 / 4 steps
1
Create the sales data lists
Create a list called days with values 1, 2, 3, 4, 5, 6, 7 and a list called sales with values 150, 200, 170, 220, 180, 210, 190.
Matplotlib
Need a hint?

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

2
Import matplotlib and create the plot
Import matplotlib.pyplot as plt. Use plt.plot(days, sales) to create a line plot.
Matplotlib
Need a hint?

Use import matplotlib.pyplot as plt and then plt.plot() with the two lists.

3
Add axis labels and format y-axis ticks
Use plt.xlabel('Day of Week') and plt.ylabel('Sales ($)') to label the axes. Then import matplotlib.ticker and use plt.gca().yaxis.set_major_formatter(matplotlib.ticker.StrMethodFormatter('${x:,.0f}')) to format y-axis ticks with dollar sign and no decimals.
Matplotlib
Need a hint?

Use plt.xlabel() and plt.ylabel() for labels. Use matplotlib.ticker.StrMethodFormatter to format y-axis ticks.

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

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