Ask Your Question
0

generate_plot_points for multiple variable functions and contour_plot

asked 2012-07-06 14:54:10 +0100

Cosmos gravatar image

updated 2014-07-19 11:30:20 +0100

vdelecroix gravatar image

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
0

answered 2014-07-20 06:31:00 +0100

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
0

answered 2014-07-18 22:53:59 +0100

Gregory Bard gravatar image

updated 2014-07-19 11:29:31 +0100

vdelecroix gravatar image

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

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

Comments

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-20 06:28:05 +0100 )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

Stats

Asked: 2012-07-06 14:54:10 +0100

Seen: 676 times

Last updated: Jul 20 '14