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.Tue, 18 Feb 2020 10:53:52 +0100Legend_fonts in list of plotshttps://ask.sagemath.org/question/49960/legend_fonts-in-list-of-plots/ Hello there,
I want to make an array of plots, and I need the font size for the legends to be reduced. I tried the code below and some variants.I really don't see what is wrng, when I try the `().set_legend_options(font_size = 8)` on a single curve, everything works fine. I tried doing this while running through a list, but did not work.
var('t')
C=[2.5, 1.7, 1, 0.7, 0.5, 0.2, 0, -0.2, -0.5, -0.8, -1, -2] # The values for c
Curves = [polar_plot(1+c*sin(t),0,t,2*pi,
legend_label = '%s'%c.n(digits=2)).set_legend_options(font_size = 8) for c in C]
Array = graphics_array(((Curves[0],Curves[2], Curves[2], Curves[3]),
(Curves[4],Curves[5], Curves[6], Curves[7]),
(Curves[8],Curves[9], Curves[10], Curves[11])))
Array.show(figsize = 9)
Thanks in advance!
Tue, 18 Feb 2020 03:45:17 +0100https://ask.sagemath.org/question/49960/legend_fonts-in-list-of-plots/Answer by eric_g for <p>Hello there,</p>
<p>I want to make an array of plots, and I need the font size for the legends to be reduced. I tried the code below and some variants.I really don't see what is wrng, when I try the <code>().set_legend_options(font_size = 8)</code> on a single curve, everything works fine. I tried doing this while running through a list, but did not work.</p>
<pre><code>var('t')
C=[2.5, 1.7, 1, 0.7, 0.5, 0.2, 0, -0.2, -0.5, -0.8, -1, -2] # The values for c
Curves = [polar_plot(1+c*sin(t),0,t,2*pi,
legend_label = '%s'%c.n(digits=2)).set_legend_options(font_size = 8) for c in C]
Array = graphics_array(((Curves[0],Curves[2], Curves[2], Curves[3]),
(Curves[4],Curves[5], Curves[6], Curves[7]),
(Curves[8],Curves[9], Curves[10], Curves[11])))
Array.show(figsize = 9)
</code></pre>
<p>Thanks in advance!</p>
https://ask.sagemath.org/question/49960/legend_fonts-in-list-of-plots/?answer=49962#post-id-49962You may use a too old version of SageMath: `graphics_array` had some issues that have been fixed in SageMath 8.9 (see [Trac #27865](https://trac.sagemath.org/ticket/27865)). The following code works well with SageMath 9.0:
var('t')
C=[2.5, 1.7, 1, 0.7, 0.5, 0.2, 0, -0.2, -0.5, -0.8, -1, -2] # The values for c
Curves = [polar_plot(1+c*sin(t),0,t,2*pi,
legend_label = '%s'%c.n(digits=2)) for c in C]
for g in Curves:
g.set_legend_options(font_size = 8)
Array = graphics_array(((Curves[0],Curves[2], Curves[2], Curves[3]),
(Curves[4],Curves[5], Curves[6], Curves[7]),
(Curves[8],Curves[9], Curves[10], Curves[11])))
Array.show(figsize = 9)
The font size is correctly taken into account. Note that the above code differs from yours by the `set_legend_options` method being called in a loop on all the graphics objects of the list `Curves`. In the original code, `Curves` was transformed into a list of outputs of this method, namely a list of `None`. Tue, 18 Feb 2020 10:53:52 +0100https://ask.sagemath.org/question/49960/legend_fonts-in-list-of-plots/?answer=49962#post-id-49962Answer by toonijn for <p>Hello there,</p>
<p>I want to make an array of plots, and I need the font size for the legends to be reduced. I tried the code below and some variants.I really don't see what is wrng, when I try the <code>().set_legend_options(font_size = 8)</code> on a single curve, everything works fine. I tried doing this while running through a list, but did not work.</p>
<pre><code>var('t')
C=[2.5, 1.7, 1, 0.7, 0.5, 0.2, 0, -0.2, -0.5, -0.8, -1, -2] # The values for c
Curves = [polar_plot(1+c*sin(t),0,t,2*pi,
legend_label = '%s'%c.n(digits=2)).set_legend_options(font_size = 8) for c in C]
Array = graphics_array(((Curves[0],Curves[2], Curves[2], Curves[3]),
(Curves[4],Curves[5], Curves[6], Curves[7]),
(Curves[8],Curves[9], Curves[10], Curves[11])))
Array.show(figsize = 9)
</code></pre>
<p>Thanks in advance!</p>
https://ask.sagemath.org/question/49960/legend_fonts-in-list-of-plots/?answer=49961#post-id-49961Hi,
.set_legend_options() does not return anything. This means that your list Curves does not contain Graphics objects. I suggest to set the legend options after you made all your plots.
var('t')
C=[2.5, 1.7, 1, 0.7, 0.5, 0.2, 0, -0.2, -0.5, -0.8, -1, -2] # The values for c
Curves = [polar_plot(1+c*sin(t),0,t,2*pi,
legend_label = '%s'%c.n(digits=2)) for c in C]
for curve in Curves:
curve.set_legend_options(font_size=8)
Array = graphics_array(((Curves[0],Curves[1], Curves[2], Curves[3]),
(Curves[4],Curves[5], Curves[6], Curves[7]),
(Curves[8],Curves[9], Curves[10], Curves[11])))
Array.show(figsize = 9)Tue, 18 Feb 2020 09:27:18 +0100https://ask.sagemath.org/question/49960/legend_fonts-in-list-of-plots/?answer=49961#post-id-49961