Ask Your Question
0

can't append to graphics object

asked 2020-09-20 21:41:24 +0200

cybervigilante gravatar image

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?

edit retag flag offensive close merge delete

Comments

If possible, please provide a minimal example to reproduce the problem.

slelievre gravatar imageslelievre ( 2020-09-21 10:12:45 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-09-21 08:33:24 +0200

Emmanuel Charpentier gravatar image

updated 2020-09-21 08:45:31 +0200

Your 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 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,

edit flag offensive delete link more

Comments

1

There 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 .

eric_g gravatar imageeric_g ( 2020-09-21 10:44:08 +0200 )edit

Thanks. multi_graphics() is what I was looking for.

cybervigilante gravatar imagecybervigilante ( 2020-09-24 01:41:34 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-09-20 21:41:24 +0200

Seen: 214 times

Last updated: Sep 21 '20