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.Wed, 23 Sep 2020 18:41:34 -0500can't append to graphics objecthttps://ask.sagemath.org/question/53519/cant-append-to-graphics-object/ I created a graphics object with grafs=Graphics() after just appending a plot to a plain list didn't seem to work.
Then I used grafs.[tab] and found it had an append attribute
So I tried appending a graphic object to it and got: AttributeError: 'Graphics' object has no attribute 'append'
I tried "add_primitive" instead of "append" and got a warning on that.
So how do I append to a graphics object and why can't it be a simple append or simple list?
Sun, 20 Sep 2020 14:41:24 -0500https://ask.sagemath.org/question/53519/cant-append-to-graphics-object/Comment by slelievre for <p>I created a graphics object with grafs=Graphics() after just appending a plot to a plain list didn't seem to work.
Then I used grafs.[tab] and found it had an append attribute
So I tried appending a graphic object to it and got: AttributeError: 'Graphics' object has no attribute 'append'
I tried "add_primitive" instead of "append" and got a warning on that.</p>
<p>So how do I append to a graphics object and why can't it be a simple append or simple list?</p>
https://ask.sagemath.org/question/53519/cant-append-to-graphics-object/?comment=53522#post-id-53522If possible, please provide a minimal example to reproduce the problem.Mon, 21 Sep 2020 03:12:45 -0500https://ask.sagemath.org/question/53519/cant-append-to-graphics-object/?comment=53522#post-id-53522Answer by Emmanuel Charpentier for <p>I created a graphics object with grafs=Graphics() after just appending a plot to a plain list didn't seem to work.
Then I used grafs.[tab] and found it had an append attribute
So I tried appending a graphic object to it and got: AttributeError: 'Graphics' object has no attribute 'append'
I tried "add_primitive" instead of "append" and got a warning on that.</p>
<p>So how do I append to a graphics object and why can't it be a simple append or simple list?</p>
https://ask.sagemath.org/question/53519/cant-append-to-graphics-object/?answer=53521#post-id-53521Your question does not specify what you want to do :
- Adding a new object to the same figure.
This is done with the `+` operator (and the related `+=` operator) :
sage: G= Graphics()
sage: G+=plot(sin,(-pi,pi))
sage: G+=plot(cos,(-pi,pi))
gets you a figure bearing two curves.
- Adding a new figure to a graphic object holding figures.
This is done by creating a [`GraphicsArray`](https://doc.sagemath.org/html/en/reference/plotting/sage/plot/multigraphics.html) object from the list of graphics you want to display :
from sage.plot.multigraphics import GraphicsArray
sage: G=GraphicsArray([plot(sin,(-pi,pi)),plot(cos,(-pi,pi))])
gets you an object holding two figures bearing one curve each.
Note that you (currently) *can't* append a new figure to an existing `GraphicsArray`:
sage: G.append([plot(exp,(-pi,1))])
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-57-a77afab4c542> in <module>
----> 1 G.append([plot(exp,(-pi,Integer(1)))])
/usr/local/sage-9/local/lib/python3.8/site-packages/sage/plot/multigraphics.py in append(self, g)
1272 """
1273 # Not clear if there is a way to do this
-> 1274 raise NotImplementedError('Appending to a graphics array is not '
1275 'yet implemented')
1276
NotImplementedError: Appending to a graphics array is not yet implemented
HTH,Mon, 21 Sep 2020 01:33:24 -0500https://ask.sagemath.org/question/53519/cant-append-to-graphics-object/?answer=53521#post-id-53521Comment by cybervigilante for <p>Your question does not specify what you want to do :</p>
<ul>
<li>Adding a new object to the same figure.</li>
</ul>
<p>This is done with the <code>+</code> operator (and the related <code>+=</code> operator) :</p>
<pre><code>sage: G= Graphics()
sage: G+=plot(sin,(-pi,pi))
sage: G+=plot(cos,(-pi,pi))
</code></pre>
<p>gets you a figure bearing two curves.</p>
<ul>
<li>Adding a new figure to a graphic object holding figures.</li>
</ul>
<p>This is done by creating a <a href="https://doc.sagemath.org/html/en/reference/plotting/sage/plot/multigraphics.html"><code>GraphicsArray</code></a> object from the list of graphics you want to display :</p>
<pre><code>from sage.plot.multigraphics import GraphicsArray
sage: G=GraphicsArray([plot(sin,(-pi,pi)),plot(cos,(-pi,pi))])
</code></pre>
<p>gets you an object holding two figures bearing one curve each.</p>
<p>Note that you (currently) <em>can't</em> append a new figure to an existing <code>GraphicsArray</code>:</p>
<pre><code>sage: G.append([plot(exp,(-pi,1))])
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-57-a77afab4c542> in <module>
----> 1 G.append([plot(exp,(-pi,Integer(1)))])
/usr/local/sage-9/local/lib/python3.8/site-packages/sage/plot/multigraphics.py in append(self, g)
1272 """
1273 # Not clear if there is a way to do this
-> 1274 raise NotImplementedError('Appending to a graphics array is not '
1275 'yet implemented')
1276
NotImplementedError: Appending to a graphics array is not yet implemented
</code></pre>
<p>HTH,</p>
https://ask.sagemath.org/question/53519/cant-append-to-graphics-object/?comment=53563#post-id-53563Thanks. multi_graphics() is what I was looking for.Wed, 23 Sep 2020 18:41:34 -0500https://ask.sagemath.org/question/53519/cant-append-to-graphics-object/?comment=53563#post-id-53563Comment by eric_g for <p>Your question does not specify what you want to do :</p>
<ul>
<li>Adding a new object to the same figure.</li>
</ul>
<p>This is done with the <code>+</code> operator (and the related <code>+=</code> operator) :</p>
<pre><code>sage: G= Graphics()
sage: G+=plot(sin,(-pi,pi))
sage: G+=plot(cos,(-pi,pi))
</code></pre>
<p>gets you a figure bearing two curves.</p>
<ul>
<li>Adding a new figure to a graphic object holding figures.</li>
</ul>
<p>This is done by creating a <a href="https://doc.sagemath.org/html/en/reference/plotting/sage/plot/multigraphics.html"><code>GraphicsArray</code></a> object from the list of graphics you want to display :</p>
<pre><code>from sage.plot.multigraphics import GraphicsArray
sage: G=GraphicsArray([plot(sin,(-pi,pi)),plot(cos,(-pi,pi))])
</code></pre>
<p>gets you an object holding two figures bearing one curve each.</p>
<p>Note that you (currently) <em>can't</em> append a new figure to an existing <code>GraphicsArray</code>:</p>
<pre><code>sage: G.append([plot(exp,(-pi,1))])
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-57-a77afab4c542> in <module>
----> 1 G.append([plot(exp,(-pi,Integer(1)))])
/usr/local/sage-9/local/lib/python3.8/site-packages/sage/plot/multigraphics.py in append(self, g)
1272 """
1273 # Not clear if there is a way to do this
-> 1274 raise NotImplementedError('Appending to a graphics array is not '
1275 'yet implemented')
1276
NotImplementedError: Appending to a graphics array is not yet implemented
</code></pre>
<p>HTH,</p>
https://ask.sagemath.org/question/53519/cant-append-to-graphics-object/?comment=53523#post-id-53523There is no need to import `GraphicsArray`: one can just use the function `graphics_array()`. Also, depending on the use case of the OP, it could be better to use `multi_graphics()`. The method `append()` is implemented there, cf. this [documentation](https://doc.sagemath.org/html/en/reference/plotting/sage/plot/multigraphics.html#sage.plot.multigraphics.MultiGraphics.append) .Mon, 21 Sep 2020 03:44:08 -0500https://ask.sagemath.org/question/53519/cant-append-to-graphics-object/?comment=53523#post-id-53523