Ask Your Question
0

X and Y values of plot points using implicit_plot

asked 2015-07-03 00:32:33 +0100

cltho2 gravatar image

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 flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2015-07-03 08:17:35 +0100

nbruin gravatar image

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.

edit flag offensive delete link more
0

answered 2015-07-03 20:12:29 +0100

dazedANDconfused gravatar image

updated 2015-07-03 21:59:50 +0100

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

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

1 follower

Stats

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

Seen: 376 times

Last updated: Jul 03 '15