0
0
Matplotlibdata~20 mins

Log scale and symlog scale in Matplotlib - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Log and Symlog Scale Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of log scale plot ticks
What will be the y-axis tick labels when using plt.yscale('log') on data ranging from 1 to 1000?
Matplotlib
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(1, 10, 10)
y = np.linspace(1, 1000, 10)
plt.plot(x, y)
plt.yscale('log')
ticks = plt.gca().get_yticks()
print(ticks)
A[1.0, 2.0, 3.0, 4.0, 5.0]
B[1.0, 10.0, 100.0, 1000.0]
C[0.1, 1.0, 10.0, 100.0, 1000.0]
D[1.0, 5.0, 25.0, 125.0, 625.0]
Attempts:
2 left
💡 Hint
Think about how log scale places ticks at powers of 10.
data_output
intermediate
2:00remaining
Effect of symlog scale on negative values
Given the data y = [-100, -10, -1, 0, 1, 10, 100], what will be the y-axis limits after applying plt.yscale('symlog', linthresh=1)?
Matplotlib
import matplotlib.pyplot as plt
import numpy as np
y = np.array([-100, -10, -1, 0, 1, 10, 100])
plt.plot(y)
plt.yscale('symlog', linthresh=1)
lims = plt.gca().get_ylim()
print(lims)
A(-110.0, 110.0)
B(-10.0, 10.0)
C(-1.0, 1.0)
D(-100.0, 100.0)
Attempts:
2 left
💡 Hint
Symlog scale extends limits slightly beyond data range to show linear region.
visualization
advanced
3:00remaining
Identify the plot with symlog scale
Which plot correctly uses symlog scale to handle data with negative and positive values near zero?
Matplotlib
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-10, 10, 400)
y = x**3
plt.figure(figsize=(8, 4))
plt.subplot(1, 2, 1)
plt.plot(x, y)
plt.yscale('log')
plt.title('Log scale')
plt.subplot(1, 2, 2)
plt.plot(x, y)
plt.yscale('symlog', linthresh=100)
plt.title('Symlog scale')
plt.tight_layout()
plt.show()
ANeither plot uses symlog scale
BThe left plot uses symlog scale
CThe right plot uses symlog scale
DBoth plots use symlog scale
Attempts:
2 left
💡 Hint
Symlog scale can show negative values near zero, log scale cannot.
🧠 Conceptual
advanced
1:30remaining
Why use symlog scale instead of log scale?
Which reason best explains why you would choose symlog scale over log scale in a plot?
ATo display categorical data with labels
BTo display only positive data with large range
CTo display data with only zero values
DTo display data with both negative and positive values including zero
Attempts:
2 left
💡 Hint
Log scale cannot show zero or negative values.
🔧 Debug
expert
2:30remaining
Identify the error in symlog scale usage
What error will this code produce and why?
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-10, 10, 100)
y = x**2
plt.plot(x, y)
plt.yscale('symlog', linthresh=-1)
plt.show()
Matplotlib
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-10, 10, 100)
y = x**2
plt.plot(x, y)
plt.yscale('symlog', linthresh=-1)
plt.show()
AValueError because linthresh must be positive
BTypeError because y is not a list
CNo error, plot displays correctly
DRuntimeWarning due to negative y values
Attempts:
2 left
💡 Hint
Check the parameter requirements for linthresh in symlog scale.