How can I add a newline to a plot\'s label (e.g. xlabel or ylabel) in matplotlib? For example,
plt.bar([1, 2], [4, 5]) plt.xlabel(\"My x label\") plt.ylabel
Your example is exactly how it's done, you use \n. You need to take off the r prefix though so python doesn't treat it as a raw string
\n