Ask Your Question
2

Get list of coordinates from plot object

asked 2012-08-22 07:35:15 +0200

Anakonda gravatar image

I'm looking for a way to get a plain list of coordinates from a plot object. For instance, after creating an implicit plot of a circle

p = implicit_plot(x^2+y^2-1,(x,-2,2),(y,-2,2))

I am able to save the image in .pdf or even .svg format (where coordinates are present), which is a very good start. What I really want, though, is a plain list of coordinates of, say, 2000 points lying on that circle. It should be possible to extract some from the .svg file, but is there a more convenient method? Maybe even one where I can set the sample size?

Thank you in advance for any suggestions.

edit retag flag offensive close merge delete

Comments

Oh, definitely don't do this from the svg file! But I'm having a lot of trouble figuring out how to access this too. Basically, the implicit plot is a matplotlib contour subplot object - but acquiring it from p.matplotlib() seems challenging. Maybe I'm missing something obvious.

kcrisman gravatar imagekcrisman ( 2012-08-24 17:08:20 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2012-08-24 17:08:57 +0200

kcrisman gravatar image

updated 2012-08-24 17:13:00 +0200

I think maybe this works. I'm not an mpl expert, but at least the points correspond to the output of p.

sage: var('y')
y
sage: p = implicit_plot(x^2+y^2-1,(x,-2,2),(y,-2,2),plot_points=4)
sage: P = p.matplotlib()
sage: R = P.get_children()[1]
sage: S = R.collections[0]
sage: S.get_paths()
[Path([[-0.66666667 -0.70833333]
 [-0.70833333 -0.66666667]
 [-0.70833333  0.66666667]
 [-0.66666667  0.70833333]
 [ 0.66666667  0.70833333]
 [ 0.70833333  0.66666667]
 [ 0.70833333 -0.66666667]
 [ 0.66666667 -0.70833333]
 [-0.66666667 -0.70833333]], None)]
sage: S = R.collections[1]
sage: S.get_paths()
[Path([[-0.66666667 -0.70833333]
 [-0.70833333 -0.66666667]
 [-0.70833333  0.66666667]
 [-0.66666667  0.70833333]
 [ 0.66666667  0.70833333]
 [ 0.70833333  0.66666667]
 [ 0.70833333 -0.66666667]
 [ 0.66666667 -0.70833333]
 [-0.66666667 -0.70833333]], None)]
edit flag offensive delete link more

Comments

Yes, this does exactly what I wanted. This is just great. I never would have guessed that descent into the depths of the matplotlib arrays. Thank you very much!

Anakonda gravatar imageAnakonda ( 2012-08-24 21:33:25 +0200 )edit

Yeah, I don't really understand it either, but the graphic itself is NOT generated by Sage, but by mpl, so you have to just try stuff. Tab-completion rules!

kcrisman gravatar imagekcrisman ( 2012-08-27 10:38:26 +0200 )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: 2012-08-22 07:35:15 +0200

Seen: 1,616 times

Last updated: Aug 24 '12