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.Sun, 23 Mar 2014 05:38:51 -0500Points making up a plothttp://ask.sagemath.org/question/11344/points-making-up-a-plot/I'd like to get the list of points that make up a sage plot so I can process it through LaTeX (eg pgfplots) and get a better looking plot. This post [here](http://ask.sagemath.org/question/1710/get-list-of-coordinates-from-plot-object) is essentially what I'm looking. I didn't really understand the code but came up with this:
x,y=var('x,y')
f(x,y)=x^2-y^2
p = implicit_plot(f(x,y)==3,(x,-3,3),(y,-3,3),plot_points=300)
P = p.matplotlib()
R = P.get_children()[1]
S = R.collections[0]
r = S.get_paths()[0]
v = r.vertices
xvals = v[:,0]
yvals = v[:,1]
Change the function to f(x,y)=x^2+y^2 and the code works properly. But the example above only gives me the list of points for the left half of the hyperbola. How can I get the list of points when the graph is disconnected? Can that be extended to get the list of points if there are multiple graphs in the same plot? Sat, 22 Mar 2014 21:31:54 -0500http://ask.sagemath.org/question/11344/points-making-up-a-plot/Answer by fidbc for <p>I'd like to get the list of points that make up a sage plot so I can process it through LaTeX (eg pgfplots) and get a better looking plot. This post <a href="http://ask.sagemath.org/question/1710/get-list-of-coordinates-from-plot-object">here</a> is essentially what I'm looking. I didn't really understand the code but came up with this:</p>
<pre><code>x,y=var('x,y')
f(x,y)=x^2-y^2
p = implicit_plot(f(x,y)==3,(x,-3,3),(y,-3,3),plot_points=300)
P = p.matplotlib()
R = P.get_children()[1]
S = R.collections[0]
r = S.get_paths()[0]
v = r.vertices
xvals = v[:,0]
yvals = v[:,1]
</code></pre>
<p>Change the function to f(x,y)=x^2+y^2 and the code works properly. But the example above only gives me the list of points for the left half of the hyperbola. How can I get the list of points when the graph is disconnected? Can that be extended to get the list of points if there are multiple graphs in the same plot? </p>
http://ask.sagemath.org/question/11344/points-making-up-a-plot/?answer=16100#post-id-16100It seems that the set of points on the right half are in `S.get_paths()[1]`. So
s = S.get_paths()[1]
w = s.vertices
xvals1 = w[:,0]
yvals1 = w[:,1]
should do the job.
Not sure if other "connected components" would appear as subsequent elements of `S.get_paths()` but it seems likely.Sun, 23 Mar 2014 05:38:51 -0500http://ask.sagemath.org/question/11344/points-making-up-a-plot/?answer=16100#post-id-16100