That's no fair comparison. The plot label from MWE2 get's never used, because there is no legend; therefore it will not raise any error.
Once you produce this legend using plt.legend()
it will of course cause the same kind of error that you'd expect from all other strings that contain MathText commands and are no raw strings.
This crashes:
import numpy as np
import matplotlib.pyplot as plt
x = np.ones(5)
plt.plot(x, x, label="$ar{x}$ (but not really)")
plt.xlabel(r"$ar{y}$ (but not really)")
plt.legend()
plt.show()
Result:
ValueError:
$ar{x}$ (but not really)
^
Expected end of text, found '$' (at char 0), (line:1, col:1)
This does not crash, as all strings are raw strings
import numpy as np
import matplotlib.pyplot as plt
x = np.ones(5)
plt.plot(x, x, label=r"$ar{x}$ (but not really)")
plt.xlabel(r"$ar{y}$ (but not really)")
plt.legend()
plt.show()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…