0
0
Matplotlibdata~30 mins

Log scale and symlog scale in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Plotting with Log Scale and Symlog Scale in Matplotlib
📖 Scenario: You are working with a small business that tracks daily sales and wants to visualize the data clearly. Some days have very low sales, and some days have very high sales. To better understand the trends, you will create plots using log scale and symlog scale.
🎯 Goal: Build two line plots using matplotlib: one with a log scale on the y-axis and another with a symmetric log scale (symlog) on the y-axis. This will help visualize data that varies widely and includes zero or negative values.
📋 What You'll Learn
Create a list called days with values from 1 to 10.
Create a list called sales with these exact values: 0, 1, 10, 100, 1000, 10000, 100000, -10, -100, 0.
Create a variable called linthresh and set it to 20.
Plot days vs sales using plt.plot().
Set the y-axis scale to log using plt.yscale('log') for the first plot.
Create a second plot with y-axis scale set to symlog using plt.yscale('symlog', linthresh=linthresh).
Show both plots with plt.show().
💡 Why This Matters
🌍 Real World
Businesses often have data that varies a lot in size, like sales or website visits. Using log or symlog scales helps visualize such data clearly, especially when some values are zero or negative.
💼 Career
Data scientists and analysts use log and symlog scales to explore and present data effectively, making it easier to spot trends and outliers.
Progress0 / 4 steps
1
Create the data lists for days and sales
Create a list called days with values from 1 to 10, and a list called sales with these exact values: 0, 1, 10, 100, 1000, 10000, 100000, -10, -100, 0.
Matplotlib
Need a hint?

Use square brackets to create lists. Make sure the values match exactly.

2
Set the linthresh variable for symlog scale
Create a variable called linthresh and set it to 20.
Matplotlib
Need a hint?

Just assign the number 20 to the variable linthresh.

3
Plot days vs sales with log scale and symlog scale
Import matplotlib.pyplot as plt. Plot days vs sales using plt.plot(). Then set the y-axis scale to log using plt.yscale('log'). Create a new figure with plt.figure(), plot the same data again, and set the y-axis scale to symlog using plt.yscale('symlog', linthresh=linthresh).
Matplotlib
Need a hint?

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

4
Show the plots
Use plt.show() to display both plots.
Matplotlib
Need a hint?

Use plt.show() once after all plots are ready to display them.