Ask Your Question
1

Getting plot data

asked 2014-01-08 23:01:13 +0100

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
2

answered 2014-01-09 04:08:23 +0100

ndomes gravatar image

For example:

C = cube()
C.json_repr(C.default_render_params())
edit flag offensive delete link more

Comments

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

rmp251 gravatar imagermp251 ( 2014-01-09 11:17:13 +0100 )edit
1

answered 2014-01-10 04:27:33 +0100

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

Comments

Thank you!

rmp251 gravatar imagermp251 ( 2014-01-10 12:09:11 +0100 )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

Stats

Asked: 2014-01-08 23:01:13 +0100

Seen: 512 times

Last updated: Jan 10 '14