Before, this code:
import matplotlib.pyplot as plt
plt.rcParams.update({
"text.usetex": True})
plt.plot([0, 1], [0, 1])
plt.xlabel('hello\nnew world')
generated a plot with centered alignment in the x label, something like here:
But now I get this left aligned text:
I am not sure if matplotlib or latex version changed, but wondering how should I adapt my code to get back to the usual center alignment.
Thank you!
\n
can be replaced by \\\
or \\newline
(as an additional \
is needed as escape character) or \linebreak
(so that it doesn't start a new paragraph).
Another option is to put the centering locally:
import matplotlib.pyplot as plt
plt.rcParams.update({
"text.usetex": True})
plt.figure(figsize=(2,2))
plt.plot([0, 1], [0, 1])
plt.xlabel('\\begin{center} hello \linebreak new world \end{center}')