GitHub

@@ -122,7 +122,7 @@ If everything is properly configured, then adding LaTeX is trivial

122122123123

```{code-cell} python3

124124

fig, ax = plt.subplots()

125-

ax.plot(x, y, 'r-', linewidth=2, label='$y=\sin(x)$', alpha=0.6)

125+

ax.plot(x, y, 'r-', linewidth=2, label=r'$y=\sin(x)$', alpha=0.6)

126126

ax.legend(loc='upper center')

127127

plt.show()

128128

```

@@ -131,7 +131,7 @@ Controlling the ticks, adding titles and so on is also straightforward

131131132132

```{code-cell} python3

133133

fig, ax = plt.subplots()

134-

ax.plot(x, y, 'r-', linewidth=2, label='$y=\sin(x)$', alpha=0.6)

134+

ax.plot(x, y, 'r-', linewidth=2, label=r'$y=\sin(x)$', alpha=0.6)

135135

ax.legend(loc='upper center')

136136

ax.set_yticks([-1, 0, 1])

137137

ax.set_title('Test plot')

@@ -163,7 +163,7 @@ x = np.linspace(-4, 4, 150)

163163

for i in range(3):

164164

m, s = uniform(-1, 1), uniform(1, 2)

165165

y = norm.pdf(x, loc=m, scale=s)

166-

current_label = f'$\mu = {m:.2}$'

166+

current_label = rf'$\mu = {m:.2}$'

167167

ax.plot(x, y, linewidth=2, alpha=0.6, label=current_label)

168168

ax.legend()

169169

plt.show()

@@ -186,7 +186,7 @@ for i in range(num_rows):

186186

m, s = uniform(-1, 1), uniform(1, 2)

187187

x = norm.rvs(loc=m, scale=s, size=100)

188188

axes[i, j].hist(x, alpha=0.6, bins=20)

189-

t = f'$\mu = {m:.2}, \quad \sigma = {s:.2}$'

189+

t = rf'$\mu = {m:.2}, \quad \sigma = {s:.2}$'

190190

axes[i, j].set(title=t, xticks=[-4, 0, 4], yticks=[])

191191

plt.show()

192192

```

@@ -419,7 +419,7 @@ x = np.linspace(-4, 4, 150)

419419

for i in range(3):

420420

m, s = uniform(-1, 1), uniform(1, 2)

421421

y = norm.pdf(x, loc=m, scale=s)

422-

current_label = f'$\mu = {m:.2}$'

422+

current_label = rf'$\mu = {m:.2}$'

423423

ax.plot(x, y, linewidth=2, alpha=0.6, label=current_label)

424424

ax.legend()

425425

plt.show()

@@ -462,8 +462,9 @@ Place all the curves in the same figure.

462462463463

The output should look like this

464464465-

```{figure} /_static/lecture_specific/matplotlib/matplotlib_ex1.png

465+

```{image} /_static/lecture_specific/matplotlib/matplotlib_ex1.png

466466

:scale: 130

467+

:align: center

467468

```

468469469470

```{exercise-end}

Read the original on github.com ↗