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.Thu, 17 Feb 2022 14:39:03 +0100TeX label and running list-variable simultaneously in a plot legend (or plot title)https://ask.sagemath.org/question/61112/tex-label-and-running-list-variable-simultaneously-in-a-plot-legend-or-plot-title/I want to use a `[... for n in ...]` to generate plots. How can I combine in a legend and/or title, TeX with the variable that runs (here $n$) to generate the list of plots? Minimal example:
some_plots=[plot(x^n,(x,0,1.1),title=r'$x^n$ where $n$ takes the value in the box
(format is not nice, though)',
legend_label=n, rgbcolor=hue(.1*n)) for n in range(0,10)]
sum(some_plots[s] for s in range(0,10))
which shows a box with colors, and, separately the title. How can I add $n$ to the box? If I combine TeX and the variable (like `$x^n$=n`) I get errors. (I cannot upload yet pictures, which would make the question very clear)Tue, 15 Feb 2022 16:15:27 +0100https://ask.sagemath.org/question/61112/tex-label-and-running-list-variable-simultaneously-in-a-plot-legend-or-plot-title/Answer by Emmanuel Charpentier for <p>I want to use a <code>[... for n in ...]</code> to generate plots. How can I combine in a legend and/or title, TeX with the variable that runs (here $n$) to generate the list of plots? Minimal example:</p>
<pre><code>some_plots=[plot(x^n,(x,0,1.1),title=r'$x^n$ where $n$ takes the value in the box
(format is not nice, though)',
legend_label=n, rgbcolor=hue(.1*n)) for n in range(0,10)]
sum(some_plots[s] for s in range(0,10))
</code></pre>
<p>which shows a box with colors, and, separately the title. How can I add $n$ to the box? If I combine TeX and the variable (like <code>$x^n$=n</code>) I get errors. (I cannot upload yet pictures, which would make the question very clear)</p>
https://ask.sagemath.org/question/61112/tex-label-and-running-list-variable-simultaneously-in-a-plot-legend-or-plot-title/?answer=61116#post-id-61116Is this :
sage: some_plots=[plot(x^u, (0,1.1), title=r"$x^n$", legend_label="$n=%d$"%u, rgbcolor=hue(0.1*u)) for u in range(0,10)]
sage: sum(some_plots)
![Overlaid plots](/upfiles/16449511278178634.png)
what you mean (up to legend placement, which I'm too lazy to fine tune...) ?Tue, 15 Feb 2022 19:57:25 +0100https://ask.sagemath.org/question/61112/tex-label-and-running-list-variable-simultaneously-in-a-plot-legend-or-plot-title/?answer=61116#post-id-61116Comment by Emmanuel Charpentier for <p>Is this :</p>
<pre><code>sage: some_plots=[plot(x^u, (0,1.1), title=r"$x^n$", legend_label="$n=%d$"%u, rgbcolor=hue(0.1*u)) for u in range(0,10)]
sage: sum(some_plots)
</code></pre>
<p><img src="/upfiles/16449511278178634.png" alt="Overlaid plots"></p>
<p>what you mean (up to legend placement, which I'm too lazy to fine tune...) ?</p>
https://ask.sagemath.org/question/61112/tex-label-and-running-list-variable-simultaneously-in-a-plot-legend-or-plot-title/?comment=61150#post-id-61150Google "string splicing" for Python abilities in this department (which are multiple...).Thu, 17 Feb 2022 14:39:03 +0100https://ask.sagemath.org/question/61112/tex-label-and-running-list-variable-simultaneously-in-a-plot-legend-or-plot-title/?comment=61150#post-id-61150Comment by c.p. for <p>Is this :</p>
<pre><code>sage: some_plots=[plot(x^u, (0,1.1), title=r"$x^n$", legend_label="$n=%d$"%u, rgbcolor=hue(0.1*u)) for u in range(0,10)]
sage: sum(some_plots)
</code></pre>
<p><img src="/upfiles/16449511278178634.png" alt="Overlaid plots"></p>
<p>what you mean (up to legend placement, which I'm too lazy to fine tune...) ?</p>
https://ask.sagemath.org/question/61112/tex-label-and-running-list-variable-simultaneously-in-a-plot-legend-or-plot-title/?comment=61124#post-id-61124sure, that solves it:) I didn't know about % and %d.Wed, 16 Feb 2022 09:46:36 +0100https://ask.sagemath.org/question/61112/tex-label-and-running-list-variable-simultaneously-in-a-plot-legend-or-plot-title/?comment=61124#post-id-61124