0
0
Matplotlibdata~10 mins

Mathematical expressions with LaTeX in Matplotlib - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to display a simple LaTeX expression on a plot.

Matplotlib
import matplotlib.pyplot as plt
plt.text(0.5, 0.5, r'$[1]$', fontsize=20, ha='center')
plt.axis('off')
plt.show()
Drag options to blanks, or click blank then click option'
A\alpha + beta = \gamma
Balpha + beta = gamma
Calpha + \beta = gamma
D\alpha + \beta = \gamma
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the backslash before Greek letters.
Not using raw string notation r'' causing escape errors.
Omitting the $ signs around the LaTeX expression.
2fill in blank
medium

Complete the code to plot the quadratic formula using LaTeX in the title.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [1, 4, 9])
plt.title(r'Quadratic formula: $x = \frac[1]{{2a}}$')
plt.show()
Drag options to blanks, or click blank then click option'
A-b \pm \sqrt{b^2 + 4ac}
Bb \pm \sqrt{b^2 - 4ac}
C-b \pm \sqrt{b^2 - 4ac}
Db \pm \sqrt{b^2 + 4ac}
Attempts:
3 left
💡 Hint
Common Mistakes
Using plus instead of minus before b.
Using plus instead of minus inside the square root.
Forgetting \pm symbol.
3fill in blank
hard

Fix the error in the LaTeX expression to correctly display the integral in the plot label.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([0, 1], [0, 1])
plt.xlabel(r'Integral: $\int_0^1 f(x) dx = [1]$')
plt.show()
Drag options to blanks, or click blank then click option'
A\frac{1}{2}
B1/2
C\frac12
D\int_0^1 f(x) dx
Attempts:
3 left
💡 Hint
Common Mistakes
Writing fractions without \frac{}{} syntax.
Repeating the integral expression instead of the result.
Using incomplete fraction commands like \frac12.
4fill in blank
hard

Fill both blanks to create a LaTeX expression for the sum of squares in the plot text.

Matplotlib
import matplotlib.pyplot as plt
plt.text(0.5, 0.5, r'Sum: $\sum_[1]=1}^n [2]^2$', fontsize=18, ha='center')
plt.axis('off')
plt.show()
Drag options to blanks, or click blank then click option'
Ai
Bj
Ck
Dn
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variables for the index and the squared term.
Using n as the index variable instead of the upper limit.
Choosing uncommon index letters like k or j.
5fill in blank
hard

Fill all three blanks to create a LaTeX expression for the binomial coefficient in the plot title.

Matplotlib
import matplotlib.pyplot as plt
plt.title(r'Binomial coefficient: $\binom[1][2] = \frac[3]!}}{{k! (n-k)!}}$')
plt.show()
Drag options to blanks, or click blank then click option'
An
Bk
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping n and k in the binomial coefficient.
Using k! in numerator instead of n!.
Forgetting to match the factorial variable with the binomial coefficient top.