Ask Your Question
2

Points making up a plot

asked 2014-03-23 03:31:54 +0200

dazedANDconfused gravatar image

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 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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2014-03-23 11:38:51 +0200

fidbc gravatar image

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

edit flag offensive delete link more

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-03-23 03:31:54 +0200

Seen: 381 times

Last updated: Mar 23 '14