ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 11 Apr 2022 07:21:58 +0200Evaluate variable in plot labelhttps://ask.sagemath.org/question/61903/evaluate-variable-in-plot-label/I have several plots with labels that I would like to evaluate. For instance
all=[plot(x^(1/(i+1)),(x,0,4), rgbcolor=hue(i/10),axes_labels=[r"$x$",r"$x^{1/(1+%d)}$"%i]) for i in range(4)]
leads to `all[2]` showing me (sorry for not being able to upload due to <60 points) the plot lablel $x^{1/(1+1)}$, which
I would like to display after evaluation ($x^{1/2}$)
By defining the function $f(i)=i+1$ in the preamble of the graph I still cannot evaluate $f$, for $i$ is not evaluated inside the list
Even supposing I would, suppose I want the exponent in digits form. I am unable to find the string splicing character which also evaluates and then displays 0.5 (instead of a single digit). Does anybody know about how to correct this syntax?
Sun, 10 Apr 2022 20:53:04 +0200https://ask.sagemath.org/question/61903/evaluate-variable-in-plot-label/Answer by Emmanuel Charpentier for <p>I have several plots with labels that I would like to evaluate. For instance</p>
<pre><code>all=[plot(x^(1/(i+1)),(x,0,4), rgbcolor=hue(i/10),axes_labels=[r"$x$",r"$x^{1/(1+%d)}$"%i]) for i in range(4)]
</code></pre>
<p>leads to <code>all[2]</code> showing me (sorry for not being able to upload due to <60 points) the plot lablel $x^{1/(1+1)}$, which
I would like to display after evaluation ($x^{1/2}$)</p>
<p>By defining the function $f(i)=i+1$ in the preamble of the graph I still cannot evaluate $f$, for $i$ is not evaluated inside the list</p>
<p>Even supposing I would, suppose I want the exponent in digits form. I am unable to find the string splicing character which also evaluates and then displays 0.5 (instead of a single digit). Does anybody know about how to correct this syntax?</p>
https://ask.sagemath.org/question/61903/evaluate-variable-in-plot-label/?answer=61906#post-id-61906What about :
![sage: all=[plot(x^(1/(i+1)),(x,0,4), rgbcolor=hue(i/10),axes_labels=[r"$x$",r"$x^{%s}$"%str(1/(1+i))]) for i in range(4)]
sage: graphics_array(all, 2, 2)
Launched png viewer for Graphics Array of size 2 x 2]
![image description](/upfiles/16496235719475571.png)Sun, 10 Apr 2022 22:45:34 +0200https://ask.sagemath.org/question/61903/evaluate-variable-in-plot-label/?answer=61906#post-id-61906Comment by c.p. for <p>What about :</p>
<pre><code>![sage: all=[plot(x^(1/(i+1)),(x,0,4), rgbcolor=hue(i/10),axes_labels=[r"$x$",r"$x^{%s}$"%str(1/(1+i))]) for i in range(4)]
sage: graphics_array(all, 2, 2)
Launched png viewer for Graphics Array of size 2 x 2]
</code></pre>
<p><img src="/upfiles/16496235719475571.png" alt="image description"></p>
https://ask.sagemath.org/question/61903/evaluate-variable-in-plot-label/?comment=61912#post-id-61912Nice, thank you!Mon, 11 Apr 2022 07:21:58 +0200https://ask.sagemath.org/question/61903/evaluate-variable-in-plot-label/?comment=61912#post-id-61912