Ask Your Question

Getting plot data

asked 2014-01-08 16:01:13 -0500

rmp251 gravatar image

Is there a way to extract the set of values used in a plot using sage/python code?

For example, if I have 3D surface plot, what is the best way to get the set of vertices, or the z-values, for the mesh? (and similarly for 2d plots) I've looked through some of the plotting source code but haven't found a straightforward way to access the underlying plot data.

Any tips would be appreciated!

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2014-01-08 21:08:23 -0500

ndomes gravatar image

For example:

C = cube()
edit flag offensive delete link more


Thanks. What about 2d plots? e.g. C = circle((0,0),5) ?

rmp251 gravatar imagermp251 ( 2014-01-09 04:17:13 -0500 )edit

answered 2014-01-09 21:27:33 -0500

ndomes gravatar image

How to deal with 2d plots?

sage: P = polygon([(0,0),(5,0),(3,3)])
sage: list(P) ; list(P[0])

[Polygon defined by 3 points]
[(0.0, 0.0), (5.0, 0.0), (3.0, 3.0)]

Looks fine, but this will not work with a circle:

sage: C = circle((0,0),5)
sage: list(C) ; list(C[0])

[Circle defined by (0.0,0.0) with r=5.0]
Traceback (click to the left of this block for traceback)
TypeError: 'Circle' object is not iterable

Embedding a 2d plot into a 3d plot seems to help:

sage: C = circle((0,0),5)
sage: C3 = C.plot3d()
sage: C3.jmol_repr(C3.default_render_params())

[[['draw line_1 diameter 1 curve {5.0 0.0 0.0}  {4.96057350657
0.626666167822 0.0}  {4.84291580564 1.24344943582 0.0}  {4.64888242944
1.84062276342 0.0}  {4.38153340022 2.40876837051 0.0}  {4.04508497187
2.93892626146 0.0}   ...

There are different representations: json_repr , jmol_repr , tachyon_repr (depending on the viewer). I don't know why, but in the case of C3 json_repr returns an empty list, so I switched to jmol_repr.

edit flag offensive delete link more


Thank you!

rmp251 gravatar imagermp251 ( 2014-01-10 05:09:11 -0500 )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


Asked: 2014-01-08 16:01:13 -0500

Seen: 112 times

Last updated: Jan 09 '14