Putting newline in matplotlib label with TeX in Python?

后端 未结 4 1061
半阙折子戏
半阙折子戏 2020-12-24 00:36

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         


        
4条回答
  •  旧巷少年郎
    2020-12-24 00:57

    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

提交回复
热议问题