Ask Your Question

# X and Y values of plot points using implicit_plot

Is there a way to get Sage to generate a list of the x and y values computed in generating a 2D implicit plot using the implicit_plot command? Thanks.

edit retag close merge delete

## 2 Answers

Sort by » oldest newest most voted

See contour_plot. The returned object from that has an attribute xy_data_array from contains the values at the grid points used to make the plot. Sage doesn't construct the contour lines itself. Matplotlib does that. See matplotlib.pyplot.contour for the relevant routine. You'd have to look there to see if matplotlib makes the computed data easily available.

more

I noticed Sage plot inner structure posted on the sidebar and after some time puzzling through the details came up with the following code to work off of:

x,y = var('x,y')
gridDim = 300
xmin = -2
xmax = 2
deltax = (xmax-xmin)/(gridDim-1)
ymin = -2
ymax = 2
deltay = (ymax-ymin)/(gridDim-1)
xvals = []
yvals = []
f(x,y)=x^2+y^2-2
P=implicit_plot(f, (x,xmin,xmax), (y,ymin,ymax),plot_points=gridDim)
C = P._objects
for i in range(0,gridDim):
for j in range(0,gridDim):
if abs(C.xy_data_array[i][j])<.02:
xvals += [xmin+j*deltax]
yvals += [ymin+i*deltay]


To look at the points on the curve add these 2 lines:

for i in range(0,len(xvals)):
print "(%f,%f),"%(xvals[i],yvals[i])


As the link showed, the default number of points is a grid of 150 by 150. I found it necessary to have a bigger grid size and the plot_points=200 makes a 200 by 200 grid of 40,000 points. The comment "Then you get the points by looking at sign changes, or values close to zero." refers to the fact that most of those points aren't plotted. The actual points that end up getting plotted from the grid are just those where f(x,y) is close to 0--I chose abs(C.xy_data_array[i][j])<.02 and have been getting expected results.

more

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

Asked: 2015-07-03 00:32:33 +0200

Seen: 131 times

Last updated: Jul 03 '15