On 05/25/2010 02:48 PM, jbeorse wrote:
Hi,
I am trying to retrieve the xy coordinates of an implicit plot, but I
am having trouble. I am able to do this with regular 2d plots without
a problem like this:
p = plot(...)
for r in p:
X = numpy.array(r.xdata)
Y = numpy.array(r.ydata)
...
With an implicit plot I can retrieve the xy_data_array like this:
ip = implicit_plot(...)
for r in ip:
XY = val.xy_data_array
but I don't understand how to interpret that data. It is an nxn list
where n is the number of plot points and it seems to depend on x, y,
and the bounding box values. Is there any way I can interpret these
results?
First, see below for what I think is a much better and more useful way
to approach this problem.
To answer your direct question, yes. Looking at the source code in
plot/contour_plot.py, an implicit plot of f(x,y) is merely a contour
plot of the level curve f(x,y)=0. Looking in the contour plot code, the
following statement generates the xy_data_array variable:
xy_data_array = [[g(x, y) for x in xsrange(*ranges[0],
include_endpoint=True)] for y in xsrange(*ranges[1], include_endpoint=True)]
So it looks like the implicit plot points are the points in the above
array that are close to zero. And it looks like
[[g(x, y) for x in xsrange(*ranges[0], include_endpoint=True)] for y in
xsrange(*ranges[1], include_endpoint=True)]
gives you the x,y coordinate pairs.
Is there any function that converts these to the simple xy
coordinates?
How about something like:
xy_points=[[(x, y) for x in xsrange(*ranges[0], include_endpoint=True)]
for y in xsrange(*ranges[1], include_endpoint=True)]
num_x=len(xy_points)
num_y=len(xy_points[0])
eps=.001
[xy_points[i][j] for i in range(num_x) for j in range(num_y) if
abs(xy_data_array[i][j])<eps]
To give context to my question, the purpose of me getting this data is
to perform a transformation on the curve, point by point. For any
implicit function that sage can plot I can to be able to perform my
transformation and view the original and the transformation side by
side.
I think it would be cool to tap into the matplotlib transform framework
here, instead of manipulating points. It would be cool to be able to do:
transform(any_sage_plot_object)
which would just tack on a matplotlib transform command in the plotting.
This would be much more general than transforming just an implicit
plot, and would be extremely useful, I think.
See http://matplotlib.sourceforge.net/users/transforms_tutorial.html for
a tutorial on using the matplotlib transformation framework.
Jason
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org