ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 03 Jul 2015 20:12:29 +0200X and Y values of plot points using implicit_plothttps://ask.sagemath.org/question/27249/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.Fri, 03 Jul 2015 00:32:33 +0200https://ask.sagemath.org/question/27249/x-and-y-values-of-plot-points-using-implicit_plot/Answer by nbruin for <p>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.</p>
https://ask.sagemath.org/question/27249/x-and-y-values-of-plot-points-using-implicit_plot/?answer=27253#post-id-27253 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.
Fri, 03 Jul 2015 08:17:35 +0200https://ask.sagemath.org/question/27249/x-and-y-values-of-plot-points-using-implicit_plot/?answer=27253#post-id-27253Answer by dazedANDconfused for <p>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.</p>
https://ask.sagemath.org/question/27249/x-and-y-values-of-plot-points-using-implicit_plot/?answer=27255#post-id-27255I noticed [Sage plot inner structure](http://ask.sagemath.org/question/8168/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[0]
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.Fri, 03 Jul 2015 20:12:29 +0200https://ask.sagemath.org/question/27249/x-and-y-values-of-plot-points-using-implicit_plot/?answer=27255#post-id-27255