ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 23 Nov 2010 03:10:30 -0600legend overlaps plothttps://ask.sagemath.org/question/7767/legend-overlaps-plot/The legend_label overlaps my plot (ie the plotted lines). How do I prevent this? It would be nice to move the legend beside or under the plot (outside of the plot axis area).
for example:
plot(cos(x), (x,-2*pi, 2*pi), legend_label='cos(x)')+plot(cos(3*x), (x,-2*pi, 2*pi), color='green', legend_label='cos(3x)')
Is it possible to get the legend to appear in a subaxes beside the plot?Tue, 16 Nov 2010 14:56:58 -0600https://ask.sagemath.org/question/7767/legend-overlaps-plot/Comment by kcrisman for <p>The legend_label overlaps my plot (ie the plotted lines). How do I prevent this? It would be nice to move the legend beside or under the plot (outside of the plot axis area).</p>
<p>for example:
plot(cos(x), (x,-2<em>pi, 2</em>pi), legend_label='cos(x)')+plot(cos(3<em>x), (x,-2</em>pi, 2*pi), color='green', legend_label='cos(3x)')</p>
<p>Is it possible to get the legend to appear in a subaxes beside the plot?</p>
https://ask.sagemath.org/question/7767/legend-overlaps-plot/?comment=22491#post-id-22491If you can give us the specific code you used, that would help. Probably this indicates some bug in our our padding for the legend, or some customization we haven't wrapped yet, but it's hard to be sure.Wed, 17 Nov 2010 05:39:21 -0600https://ask.sagemath.org/question/7767/legend-overlaps-plot/?comment=22491#post-id-22491Answer by John Palmieri for <p>The legend_label overlaps my plot (ie the plotted lines). How do I prevent this? It would be nice to move the legend beside or under the plot (outside of the plot axis area).</p>
<p>for example:
plot(cos(x), (x,-2<em>pi, 2</em>pi), legend_label='cos(x)')+plot(cos(3<em>x), (x,-2</em>pi, 2*pi), color='green', legend_label='cos(3x)')</p>
<p>Is it possible to get the legend to appear in a subaxes beside the plot?</p>
https://ask.sagemath.org/question/7767/legend-overlaps-plot/?answer=11791#post-id-11791You can do something like this:
sage: P = plot(cos(x), (x,-2*pi, 2*pi), legend_label='cos(x)')+plot(cos(3*x), (x,-2*pi, 2*pi), color='green', legend_label='cos(3x)')
sage: P.ymin(-1.5)
Then evaluating `P` will yield this picture:
![image description](/upfiles/12900361393382653.png)
Is this the sort of thing you want? Note that you could also include `ymin=-1.5` in the command defining the plot:
sage: plot(cos(x), (x,-2*pi, 2*pi), legend_label='cos(x)')+plot(cos(3*x), (x,-2*pi, 2*pi), color='green', legend_label='cos(3x)', ymin=-1.5)
Wed, 17 Nov 2010 11:24:50 -0600https://ask.sagemath.org/question/7767/legend-overlaps-plot/?answer=11791#post-id-11791Comment by kcrisman for <p>You can do something like this:</p>
<pre><code>sage: P = plot(cos(x), (x,-2*pi, 2*pi), legend_label='cos(x)')+plot(cos(3*x), (x,-2*pi, 2*pi), color='green', legend_label='cos(3x)')
sage: P.ymin(-1.5)
</code></pre>
<p>Then evaluating <code>P</code> will yield this picture:
<img alt="image description" src="/upfiles/12900361393382653.png"/></p>
<p>Is this the sort of thing you want? Note that you could also include <code>ymin=-1.5</code> in the command defining the plot:</p>
<pre><code>sage: plot(cos(x), (x,-2*pi, 2*pi), legend_label='cos(x)')+plot(cos(3*x), (x,-2*pi, 2*pi), color='green', legend_label='cos(3x)', ymin=-1.5)
</code></pre>
https://ask.sagemath.org/question/7767/legend-overlaps-plot/?comment=22482#post-id-22482Nice! Although it might still be worth filing a ticket... if mpl/Sage can detect when the plot touches the stuff. Or to add this great example to the documentation!Wed, 17 Nov 2010 15:54:41 -0600https://ask.sagemath.org/question/7767/legend-overlaps-plot/?comment=22482#post-id-22482Comment by kcrisman for <p>You can do something like this:</p>
<pre><code>sage: P = plot(cos(x), (x,-2*pi, 2*pi), legend_label='cos(x)')+plot(cos(3*x), (x,-2*pi, 2*pi), color='green', legend_label='cos(3x)')
sage: P.ymin(-1.5)
</code></pre>
<p>Then evaluating <code>P</code> will yield this picture:
<img alt="image description" src="/upfiles/12900361393382653.png"/></p>
<p>Is this the sort of thing you want? Note that you could also include <code>ymin=-1.5</code> in the command defining the plot:</p>
<pre><code>sage: plot(cos(x), (x,-2*pi, 2*pi), legend_label='cos(x)')+plot(cos(3*x), (x,-2*pi, 2*pi), color='green', legend_label='cos(3x)', ymin=-1.5)
</code></pre>
https://ask.sagemath.org/question/7767/legend-overlaps-plot/?comment=22476#post-id-22476I think this would have to be 4.6; legend labels were pretty recently introduced (from matplotlib).Tue, 23 Nov 2010 03:10:30 -0600https://ask.sagemath.org/question/7767/legend-overlaps-plot/?comment=22476#post-id-22476Comment by ryan for <p>You can do something like this:</p>
<pre><code>sage: P = plot(cos(x), (x,-2*pi, 2*pi), legend_label='cos(x)')+plot(cos(3*x), (x,-2*pi, 2*pi), color='green', legend_label='cos(3x)')
sage: P.ymin(-1.5)
</code></pre>
<p>Then evaluating <code>P</code> will yield this picture:
<img alt="image description" src="/upfiles/12900361393382653.png"/></p>
<p>Is this the sort of thing you want? Note that you could also include <code>ymin=-1.5</code> in the command defining the plot:</p>
<pre><code>sage: plot(cos(x), (x,-2*pi, 2*pi), legend_label='cos(x)')+plot(cos(3*x), (x,-2*pi, 2*pi), color='green', legend_label='cos(3x)', ymin=-1.5)
</code></pre>
https://ask.sagemath.org/question/7767/legend-overlaps-plot/?comment=22478#post-id-22478This will work for the current project that I'm working on. However, I would like to see if sage could automatically handle situations like these.Mon, 22 Nov 2010 01:00:00 -0600https://ask.sagemath.org/question/7767/legend-overlaps-plot/?comment=22478#post-id-22478Comment by mandrake for <p>You can do something like this:</p>
<pre><code>sage: P = plot(cos(x), (x,-2*pi, 2*pi), legend_label='cos(x)')+plot(cos(3*x), (x,-2*pi, 2*pi), color='green', legend_label='cos(3x)')
sage: P.ymin(-1.5)
</code></pre>
<p>Then evaluating <code>P</code> will yield this picture:
<img alt="image description" src="/upfiles/12900361393382653.png"/></p>
<p>Is this the sort of thing you want? Note that you could also include <code>ymin=-1.5</code> in the command defining the plot:</p>
<pre><code>sage: plot(cos(x), (x,-2*pi, 2*pi), legend_label='cos(x)')+plot(cos(3*x), (x,-2*pi, 2*pi), color='green', legend_label='cos(3x)', ymin=-1.5)
</code></pre>
https://ask.sagemath.org/question/7767/legend-overlaps-plot/?comment=22477#post-id-22477Which version does that work in? I tried copy&pasting your code in notebook and in sage prompt, and it doesn't work for me in 4.5.3. I get a RuntimeError in line(), illegal option `legend_label`. Are you using some other plot lib? Can you complete your example with the necessary import ... in that case?Tue, 23 Nov 2010 02:54:39 -0600https://ask.sagemath.org/question/7767/legend-overlaps-plot/?comment=22477#post-id-22477