Challenge - 5 Problems
LaTeX Plot Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of LaTeX formatted plot title
What will be the title text shown on the plot after running this code?
Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [1, 4, 9]) plt.title(r'$y = x^2$') plt.show()
Attempts:
2 left
💡 Hint
Look at how LaTeX math expressions are wrapped with $ signs inside the raw string.
✗ Incorrect
Using r'$y = x^2$' in plt.title tells matplotlib to render the text as a LaTeX math expression, so the superscript 2 appears correctly.
❓ data_output
intermediate2:00remaining
Number of tick labels with LaTeX formatting
How many x-axis tick labels will be shown after running this code?
Matplotlib
import matplotlib.pyplot as plt import numpy as np x = np.linspace(0, 2, 5) plt.plot(x, x**2) plt.xticks(x, [f'$x_{{{int(i)}}}$' for i in x]) plt.show()
Attempts:
2 left
💡 Hint
Look carefully at how the labels are created using int(i) for each tick value.
✗ Incorrect
The labels use int(i) which truncates decimals, so 0.5 and 1.5 become 0 and 1 respectively, causing repeated labels.
❓ visualization
advanced2:00remaining
Correct LaTeX rendering of integral expression in plot
Which option produces a plot with the title showing the integral \( \int_0^1 x^2 dx \) correctly formatted?
Attempts:
2 left
💡 Hint
Raw strings (r'') help avoid needing to double escape backslashes in LaTeX.
✗ Incorrect
Option D uses a raw string with proper LaTeX math delimiters, so the integral renders correctly. Option D misses raw string so backslash escapes may fail. Options A and D miss math delimiters or have wrong escaping.
🔧 Debug
advanced2:00remaining
Identify the error in LaTeX expression for plot label
What error will this code produce when run?
Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [1, 4, 9]) plt.xlabel(r'$\frac{1}{2$') plt.show()
Attempts:
2 left
💡 Hint
Check if all braces in the LaTeX expression are properly closed.
✗ Incorrect
The LaTeX expression has an opening brace '{' without a matching closing brace '}', causing matplotlib to raise a runtime error when rendering.
🚀 Application
expert3:00remaining
Create a plot with multiple LaTeX formatted annotations
Which code snippet correctly adds two LaTeX formatted annotations at points (1,1) and (2,4) on the plot?
Attempts:
2 left
💡 Hint
Raw strings with $ delimiters are needed for LaTeX math rendering in annotations.
✗ Incorrect
Option C uses raw strings with $...$ which matplotlib interprets as LaTeX math, so annotations render correctly. Option C misses raw string so backslash escapes may fail. Options C and D miss $ delimiters so no math formatting.