Challenge - 5 Problems
Axis Scale Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of linear vs log scale plot commands
What will be the y-axis limits after running this code snippet?
Matplotlib
import matplotlib.pyplot as plt import numpy as np x = np.linspace(1, 10, 10) y = x ** 2 plt.plot(x, y) plt.yscale('log') plt.ylim(1, 100) plt.show() print(plt.gca().get_ylim())
Attempts:
2 left
💡 Hint
Remember that plt.ylim sets limits directly, even if scale is log.
✗ Incorrect
The plt.ylim(1, 100) sets the y-axis limits explicitly. Even with log scale, the limits remain (1.0, 100.0).
❓ data_output
intermediate2:00remaining
Number of ticks on log scale axis
How many major ticks will appear on the y-axis after running this code?
Matplotlib
import matplotlib.pyplot as plt import numpy as np x = np.linspace(1, 100, 100) y = x plt.plot(x, y) plt.yscale('log') plt.show() print(len(plt.gca().get_yticks()))
Attempts:
2 left
💡 Hint
Log scale major ticks usually appear at powers of 10.
✗ Incorrect
The y-axis ranges from 1 to 100, so major ticks appear at 1, 10, 100, totaling 3 major ticks.
❓ visualization
advanced3:00remaining
Identify the plot with log scale on y-axis
Which plot shows a straight line when y = 10^x is plotted?
Matplotlib
import matplotlib.pyplot as plt import numpy as np x = np.linspace(0, 3, 100) y = 10 ** x plt.figure(figsize=(8, 4)) plt.subplot(1, 2, 1) plt.plot(x, y) plt.title('Plot 1') plt.subplot(1, 2, 2) plt.plot(x, y) plt.yscale('log') plt.title('Plot 2') plt.show()
Attempts:
2 left
💡 Hint
Log scale turns exponential curves into straight lines.
✗ Incorrect
Plot 2 uses a log scale on y-axis, so y=10^x appears as a straight line.
🧠 Conceptual
advanced2:00remaining
Effect of log scale on zero or negative values
What happens if you set y-axis to log scale but your data contains zero or negative values?
Attempts:
2 left
💡 Hint
Logarithm of zero or negative numbers is undefined.
✗ Incorrect
Matplotlib raises a warning or error and ignores zero or negative values when using log scale.
🔧 Debug
expert3:00remaining
Why does this log scale plot show empty y-axis?
Given this code, why does the plot show no data on y-axis?
Matplotlib
import matplotlib.pyplot as plt import numpy as np x = np.linspace(0, 10, 100) y = np.sin(x) plt.plot(x, y) plt.yscale('log') plt.show()
Attempts:
2 left
💡 Hint
Check the range of y values and log scale requirements.
✗ Incorrect
The sine function produces negative values, which cannot be shown on a log scale y-axis.