Putting newline in matplotlib label with TeX in Python?

后端 未结 4 1058
半阙折子戏
半阙折子戏 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 01:02

    plt.bar([1, 2], [4, 5])
    plt.xlabel("My x label")
    plt.ylabel(r"My long label with $\Sigma_{C}$ math" + "\n" + "continues here")
    

    Just concatenate the strings with a newline that isn't in raw string form.

提交回复
热议问题