Ask Your Question
1

Strange Error Message when Plotting with a LaTeX Legend

asked 2020-07-01 01:28:17 +0100

Gregory Bard gravatar image

updated 2020-07-01 01:29:45 +0100

The following code is from the 1st edition of my textbook, Sage for Undergraduates. It is producing some extremely unexpected errors (technically, deprication warnings). Something about an invalid escape sequence, \i, which I'm not using.

Can someone explain how I should change my code, so that these warnings do not appear?

Code:

P1= text('$\int_0^2 \sqrt{x} \, dx$', (0.5, 1.1), fontsize=20)

P2= plot( sqrt(x), 0, 2, fill=True)

P= P1 + P2

P.show()

Warning: <input>:1: DeprecationWarning: invalid escape sequence \i

Quick Link: https://sagecell.sagemath.org/?z=eJwV...

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2020-07-01 02:26:37 +0100

Juanjo gravatar image

The problem comes from the first line. It should be:

P1= text(r'$\int_0^2 \sqrt{x} \, dx$', (0.5, 1.1), fontsize=20)

Please, note the r (which means raw) before the string. It is needed to force Python to interpret \ as an ordinary character instead of an escape one.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-07-01 01:28:17 +0100

Seen: 501 times

Last updated: Jul 01 '20