ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 02 Aug 2016 14:50:21 -0500latex in plotshttp://ask.sagemath.org/question/33805/latex-in-plots/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?Wed, 15 Jun 2016 16:05:48 -0500http://ask.sagemath.org/question/33805/latex-in-plots/Answer by calc314 for <p>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:</p>
<pre><code>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)
</code></pre>
<p>Everything works fine except for two things in the displayed formula:</p>
<ol>
<li>the * s are shown (which I can live with)</li>
<li>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.</li>
</ol>
<p><strong>Are there better ways of doing this?</strong></p>
<p>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?</p>
http://ask.sagemath.org/question/33805/latex-in-plots/?answer=33807#post-id-33807Use 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.Wed, 15 Jun 2016 18:04:11 -0500http://ask.sagemath.org/question/33805/latex-in-plots/?answer=33807#post-id-33807Comment by k1monfared for <p>Use the <code>latex</code> command to convert your functions to a proper typesetting.</p>
<pre><code>R = text(r"$%s \approx %s$" %(latex(f),latex(g)),(0,yzoom[1]+1),rgbcolor=(1,0,0))
</code></pre>
<p>I don't know about the color issue.</p>
http://ask.sagemath.org/question/33805/latex-in-plots/?comment=34305#post-id-34305I didn't know I can use latex command inside a text command. Thanks, that helps.Tue, 02 Aug 2016 14:50:21 -0500http://ask.sagemath.org/question/33805/latex-in-plots/?comment=34305#post-id-34305