2

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.

1 Answer 1

6

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.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.