# Getting plot data

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 close merge delete

Sort by » oldest newest most voted For example:

C = cube()
C.json_repr(C.default_render_params())

more

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

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

[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)

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

more