ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 20 Jul 2014 06:31:00 +0200generate_plot_points for multiple variable functions and contour_plothttps://ask.sagemath.org/question/9140/generate_plot_points-for-multiple-variable-functions-and-contour_plot/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](https://groups.google.com/forum/?fromgroups#!topic/sage-devel/ax09DwbbnGo):
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 :)
Fri, 06 Jul 2012 14:54:10 +0200https://ask.sagemath.org/question/9140/generate_plot_points-for-multiple-variable-functions-and-contour_plot/Answer by Gregory Bard for <p>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.</p>
<p>Example from documentation:</p>
<pre><code>sage: from sage.plot.plot import generate_plot_points
sage: generate_plot_points(sin, (0, pi), plot_points=2, adaptive_recursion=0)
</code></pre>
<p>I guess one could solve symbolically let's say a contour equation and then create the values i talk about like discussed <a href="https://groups.google.com/forum/?fromgroups#!topic/sage-devel/ax09DwbbnGo">here</a>:</p>
<pre><code>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)]
</code></pre>
<p>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 :)</p>
https://ask.sagemath.org/question/9140/generate_plot_points-for-multiple-variable-functions-and-contour_plot/?answer=23476#post-id-23476The 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 ) Fri, 18 Jul 2014 22:53:59 +0200https://ask.sagemath.org/question/9140/generate_plot_points-for-multiple-variable-functions-and-contour_plot/?answer=23476#post-id-23476Comment by kcrisman for <p>The function you are looking for is <strong>contour_plot</strong>. The following works:</p>
<pre><code>var("y")
contour_plot( y^2 - x^3 - x == 0, (x,-5,5), (y,-5,5), fill=False, axes=true )
</code></pre>
https://ask.sagemath.org/question/9140/generate_plot_points-for-multiple-variable-functions-and-contour_plot/?comment=23496#post-id-23496I 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.Sun, 20 Jul 2014 06:28:05 +0200https://ask.sagemath.org/question/9140/generate_plot_points-for-multiple-variable-functions-and-contour_plot/?comment=23496#post-id-23496Answer by kcrisman for <p>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.</p>
<p>Example from documentation:</p>
<pre><code>sage: from sage.plot.plot import generate_plot_points
sage: generate_plot_points(sin, (0, pi), plot_points=2, adaptive_recursion=0)
</code></pre>
<p>I guess one could solve symbolically let's say a contour equation and then create the values i talk about like discussed <a href="https://groups.google.com/forum/?fromgroups#!topic/sage-devel/ax09DwbbnGo">here</a>:</p>
<pre><code>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)]
</code></pre>
<p>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 :)</p>
https://ask.sagemath.org/question/9140/generate_plot_points-for-multiple-variable-functions-and-contour_plot/?answer=23497#post-id-23497I'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](http://stackoverflow.com/questions/18304722/python-find-contour-lines-from-matplotlib-pyplot-contour) or [this one](http://stackoverflow.com/questions/5666056/matplotlib-extracting-data-from-contour-lines) 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.Sun, 20 Jul 2014 06:31:00 +0200https://ask.sagemath.org/question/9140/generate_plot_points-for-multiple-variable-functions-and-contour_plot/?answer=23497#post-id-23497