0
0
Matplotlibdata~30 mins

Axis scales (linear, log) in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Axis scales (linear, log) with matplotlib
📖 Scenario: You are analyzing sales data that grows exponentially. You want to see how the sales look on a normal scale and on a logarithmic scale to better understand the growth pattern.
🎯 Goal: Create a simple line plot of sales data using matplotlib. First, plot the data with a linear scale on the y-axis. Then, change the y-axis scale to logarithmic to compare the views.
📋 What You'll Learn
Create a list called sales with the values: 10, 100, 1000, 10000, 100000
Create a list called months with the values: 1, 2, 3, 4, 5
Create a variable called y_scale and set it to the string 'linear'
Use matplotlib to plot months vs sales with the y-axis scale set to y_scale
Change the value of y_scale to 'log' and plot the same data again
Print the plots so the output shows both linear and logarithmic scale plots
💡 Why This Matters
🌍 Real World
Scientists and business analysts often use logarithmic scales to better understand data that grows exponentially or covers a wide range.
💼 Career
Knowing how to change axis scales in plots is important for data visualization roles and helps communicate insights clearly.
Progress0 / 4 steps
1
Create the sales and months data lists
Create a list called sales with the values 10, 100, 1000, 10000, and 100000. Also create a list called months with the values 1, 2, 3, 4, and 5.
Matplotlib
Need a hint?

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

2
Set the initial y-axis scale to linear
Create a variable called y_scale and set it to the string 'linear'.
Matplotlib
Need a hint?

Assign the string 'linear' to the variable y_scale.

3
Plot the sales data with the y-axis scale set to y_scale
Import matplotlib.pyplot as plt. Use plt.plot() to plot months on the x-axis and sales on the y-axis. Then set the y-axis scale using plt.yscale(y_scale). Finally, add a title 'Sales Data with Linear Scale' and call plt.show() to display the plot.
Matplotlib
Need a hint?

Remember to import matplotlib.pyplot as plt. Use plt.plot() and plt.yscale() to set the scale.

4
Change y_scale to 'log' and plot again
Change the value of y_scale to the string 'log'. Then plot months vs sales again using plt.plot(), set the y-axis scale with plt.yscale(y_scale), add the title 'Sales Data with Logarithmic Scale', and call plt.show() to display the plot.
Matplotlib
Need a hint?

Assign 'log' to y_scale and repeat the plotting steps with the new scale.