ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 10 Jan 2014 05:09:11 -0600Getting plot datahttp://ask.sagemath.org/question/10882/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!Wed, 08 Jan 2014 16:01:13 -0600http://ask.sagemath.org/question/10882/getting-plot-data/Answer by ndomes for <p>Is there a way to extract the set of values used in a plot using sage/python code?</p>
<p>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. </p>
<p>Any tips would be appreciated!</p>
http://ask.sagemath.org/question/10882/getting-plot-data/?answer=15904#post-id-15904How 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.
Thu, 09 Jan 2014 21:27:33 -0600http://ask.sagemath.org/question/10882/getting-plot-data/?answer=15904#post-id-15904Comment by rmp251 for <p>How to deal with 2d plots?</p>
<pre><code>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)]
</code></pre>
<p>Looks fine, but this will not work with a circle:</p>
<pre><code>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
</code></pre>
<p>Embedding a 2d plot into a 3d plot seems to help:</p>
<pre><code>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} ...
</code></pre>
<p>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.</p>
http://ask.sagemath.org/question/10882/getting-plot-data/?comment=16460#post-id-16460Thank you!Fri, 10 Jan 2014 05:09:11 -0600http://ask.sagemath.org/question/10882/getting-plot-data/?comment=16460#post-id-16460Answer by ndomes for <p>Is there a way to extract the set of values used in a plot using sage/python code?</p>
<p>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. </p>
<p>Any tips would be appreciated!</p>
http://ask.sagemath.org/question/10882/getting-plot-data/?answer=15898#post-id-15898For example:
C = cube()
C.json_repr(C.default_render_params())Wed, 08 Jan 2014 21:08:23 -0600http://ask.sagemath.org/question/10882/getting-plot-data/?answer=15898#post-id-15898Comment by rmp251 for <p>For example:</p>
<pre><code>C = cube()
C.json_repr(C.default_render_params())
</code></pre>
http://ask.sagemath.org/question/10882/getting-plot-data/?comment=16463#post-id-16463Thanks. What about 2d plots? e.g.
C = circle((0,0),5)
?Thu, 09 Jan 2014 04:17:13 -0600http://ask.sagemath.org/question/10882/getting-plot-data/?comment=16463#post-id-16463