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