Ask Your Question
0

can't append to graphics object

asked 4 years ago

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?

Preview: (hide)

Comments

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

slelievre gravatar imageslelievre ( 4 years ago )

1 Answer

Sort by » oldest newest most voted
1

answered 4 years ago

Emmanuel Charpentier gravatar image

updated 4 years ago

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,

Preview: (hide)
link

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 ( 4 years ago )

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

cybervigilante gravatar imagecybervigilante ( 4 years ago )

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: 4 years ago

Seen: 335 times

Last updated: Sep 21 '20