Ask Your Question

generate_plot_points for multiple variable functions and contour_plot

asked 2012-07-06 07:54:10 -0500

Cosmos gravatar image

updated 2014-07-19 04:30:20 -0500

Is there a default sage function to generate all (x,y,f(x,y)) values the program uses to draw a multivariable function or the contours of let's say a f(x,y)=C ? I am new to sage and could only find that generate_plot_points works only for one variable functions.

Example from documentation:

sage: from sage.plot.plot import generate_plot_points
sage: generate_plot_points(sin, (0, pi), plot_points=2, adaptive_recursion=0)

I guess one could solve symbolically let's say a contour equation and then create the values i talk about like discussed here:

sage: var('x,y')
(x, y)
sage: solve(y^2 - x^3 - x == 0, [y])
[y == -sqrt(x)*sqrt(x^2 + 1), y == sqrt(x)*sqrt(x^2 + 1)]

then just plot each of those two above and combine them. But this could become really cumbersome since one could have a terribly complicated equation. So can this be done currently or someone needs a workaround to achieve this? excuse my english :)

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2014-07-19 23:31:00 -0500

kcrisman gravatar image

I'm not sure how easy this is. The problem is that Sage doesn't actually do anything with this until it's requested to be shown as a figure.

The magic is done by contourf in matplotlib. You may find this question or this one helpful, though no guarantees. You can create a Matplotlib object from a Sage one by doing something C = implicit_plot(...) and then c = C.matplotlib(). But you'd still have to extract stuff from it and I'm not an mpl expert, here one exits Sage territory since mpl thinks differently about plots - data, not functions.

edit flag offensive delete link more

answered 2014-07-18 15:53:59 -0500

Gregory Bard gravatar image

updated 2014-07-19 04:29:31 -0500

The function you are looking for is contour_plot. The following works:

contour_plot( y^2 - x^3 - x == 0, (x,-5,5), (y,-5,5), fill=False, axes=true )
edit flag offensive delete link more


I believe the OP is asking how to acquire the specific *points* Sage (really, matplotlib, in this case) uses, though, not to do the plotting. I'm not sure mpl really thinks that way about its plots, though.

kcrisman gravatar imagekcrisman ( 2014-07-19 23:28:05 -0500 )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


Asked: 2012-07-06 07:54:10 -0500

Seen: 285 times

Last updated: Jul 19 '14