Ask Your Question
0

latex in plots

asked 2016-06-15 23:05:48 +0100

k1monfared gravatar image

I want to display the formula for the graph of a function that sage has plotted without typing the expression manually, because sage has calculated it. For example the n-th Taylor polynomial expansion of a function:

f = sin(x)
g = f.taylor(x, 0, 13)
P = plot(f,(x,-10, 10), ymin =-4, ymax = 4, color="blue", axes=True, aspect_ratio=1, thickness=3)
Q = plot(g,(x,-10, 10), ymin =-4, ymax = 4, color="red", axes=True, aspect_ratio=1)
R = text(r"$%s \approx %s$" %(f,g),(0,yzoom[1]+1),rgbcolor=(1,0,0))
show(P + Q + R)

Everything works fine except for two things in the displayed formula:

  1. the * s are shown (which I can live with)
  2. The two digit exponents are not shown correctly which I assume it is because there are no curly brackets around them in the string g.

Are there better ways of doing this?

P.S. Are there ways of writing up the parts of the text in different colors, without defining two pieces of text and trying to figure out their relative positions?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2016-06-16 01:04:11 +0100

calc314 gravatar image

Use the latex command to convert your functions to a proper typesetting.

R = text(r"$%s \approx %s$" %(latex(f),latex(g)),(0,yzoom[1]+1),rgbcolor=(1,0,0))

I don't know about the color issue.

edit flag offensive delete link more

Comments

I didn't know I can use latex command inside a text command. Thanks, that helps.

k1monfared gravatar imagek1monfared ( 2016-08-02 21:50:21 +0100 )edit

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: 2016-06-15 23:05:48 +0100

Seen: 1,300 times

Last updated: Jun 16 '16