For matplotlib, you can label legends and axis labels using tex command syntax. You're supposed to prepend r to the string: r"my tex label". But what I don't understand is why the legend label doesn't care and yet the axis label does care.
Why do the axis labels behave differently than the legend label (or vice versa)?
MWE1 - Crashes
## Hello World! I crash!
import numpy as np
import matplotlib.pyplot as plt
x = np.ones(5)
plt.plot(x, x, label="$\bar{x}$ (but not really)")
plt.xlabel("$\bar{y}$ (but not really)") # I cause the crash
plt.show()
MWE2 - Doesn't Crash
import numpy as np
import matplotlib.pyplot as plt
x = np.ones(5)
plt.plot(x, x, label="$\bar{x}$ (but not really)") # I still don't need prepended r
plt.xlabel(r"$\bar{y}$ (but not really)")
plt.show()