matplotlib原始字符串换行代码

use*_*133 2 python matplotlib

matplotlib文本字段的代码中的字符或字符串是什么来打破该行以避免代码行太长?

例如:

plt.text(0.5, 0.5,
    r'$\mathsf{sin\left(\frac{\pi}{180} f_1 \theta + \varphi_1\right) + B sin\left(\frac{\pi}{180} f_2 \theta + \varphi_2\right)}$'
Run Code Online (Sandbox Code Playgroud)

利用"\"突破长线收益率在未格式化的文本打印.

DSM*_*DSM 6

我通常利用字符串文字串联.IOW,如果你的琴弦彼此相邻而没有任何干预操作员,那么他们会自动加入:

>>> "a" + "b"
'ab'
>>> "a" "b"
'ab'
Run Code Online (Sandbox Code Playgroud)

所以

plt.text(0.5, 0.5,
         r'$\mathsf{sin\left(\frac{\pi}{180} f_1 \theta + \varphi_1\right)'
         r'     + B sin\left(\frac{\pi}{180} f_2 \theta + \varphi_2\right)}$')
Run Code Online (Sandbox Code Playgroud)

也有效.(因为这是TeX,我添加了一些额外的空格来使两条线对齐;如果我们正在使用一些更加白空间敏感的东西,那将无效.)