Reputation: 2993
What is the character or chain of characters in the code of matplotlib text field to break the line so as to avoid having too long code lines?
for example:
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)}$'
using "\"
to break the long line yields in printing in unformatted text.
Upvotes: 2
Views: 1178
Reputation: 353429
I usually take advantage of string literal concatenation. IOW, if you have strings right next to each other without any intervening operator then they're automatically joined:
>>> "a" + "b"
'ab'
>>> "a" "b"
'ab'
and so
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)}$')
works too. (Since this is TeX I added some extra spaces to bring the two lines into alignment; if we were working with something which was more white-space sensitive that wouldn't work.)
Upvotes: 6