Ask Your Question
0

generate_plot_points for multiple variable functions and contour_plot

asked 12 years ago

Cosmos gravatar image

updated 10 years ago

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 :)

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
0

answered 10 years ago

Gregory Bard gravatar image

updated 10 years ago

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 )
Preview: (hide)
link

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 ( 10 years ago )
0

answered 10 years ago

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.

Preview: (hide)
link

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: 12 years ago

Seen: 708 times

Last updated: Jul 20 '14