implicit plotting

31 views
Skip to first unread message

ma...@mendelu.cz

unread,
Oct 13, 2009, 6:05:09 PM10/13/09
to sage-support
Hello all, is there any other possibility how to plot implicit
function than implicitplot?

I do not like implicitplot too much, since it is in fact countourplot
and it is not easy to set the color (for example).

Thanks
Robert Marik

kcrisman

unread,
Oct 13, 2009, 8:07:59 PM10/13/09
to sage-support
There is not currently any other way to do this, I think. A colleague
of mine has some experimental code to implicit plot the "right" way
(by following derivatives around and spot-checking nearby to not miss
components, I guess), but doesn't consider it ready for prime time
yet.

At last most machines are now fast enough to do a reasonable version
using our current code, as note that we recently increased the default
number of plot points. Still, I really wish I knew how things like
Mac's Grapher did stuff like this, because I don't think they use a
contour plot and the graphs look SO good.

Sorry. It might be worth checking the Internet to see if anyone uses
matplotlib to do implicit plots and has some custom code for this.

- kcrisman

Jason Grout

unread,
Oct 13, 2009, 8:06:35 PM10/13/09
to sage-s...@googlegroups.com


What would you like to do?

Jason

--
Jason Grout

Jason Grout

unread,
Oct 13, 2009, 10:44:36 PM10/13/09
to sage-s...@googlegroups.com
kcrisman wrote:
>
>
> On Oct 13, 6:05 pm, "ma...@mendelu.cz" <ma...@mendelu.cz> wrote:
>> Hello all, is there any other possibility how to plot implicit
>> function than implicitplot?
>>
>> I do not like implicitplot too much, since it is in fact countourplot
>> and it is not easy to set the color (for example).
>
> There is not currently any other way to do this, I think. A colleague
> of mine has some experimental code to implicit plot the "right" way
> (by following derivatives around and spot-checking nearby to not miss
> components, I guess), but doesn't consider it ready for prime time
> yet.


How do you do an implicit plot "right"? Scipy has tools for numerical
integration (you mention following derivatives), if that helps.

A quick google search turns up several references to software:
http://geomblog.blogspot.com/2008/01/plotting-implicit-functions-bleg.html

The maple help page may help:
http://www.maplesoft.com/support/help/Maple/view.aspx?path=plots/implicitplot

This issue has come up before on the list (and Josh Kantor gave an
algorithm and a reference):
https://groups.google.com/group/sage-devel/browse_thread/thread/6b1d3d0f06db9c6a

More references and algorithms:
http://www.tangentspace.net/cz/archives/2007/08/implicit-plotting-code-for-mathematica/

Mma also says: ContourPlot initially evaluates f at a grid of equally
spaced sample points specified by PlotPoints. Then it uses an adaptive
algorithm to subdivide at most MaxRecursion times to generate smooth
contours. http://reference.wolfram.com/mathematica/ref/ContourPlot.html

Jason


--
Jason Grout

William Stein

unread,
Oct 13, 2009, 11:27:14 PM10/13/09
to sage-s...@googlegroups.com
On Tue, Oct 13, 2009 at 7:44 PM, Jason Grout
<jason...@creativetrax.com> wrote:
>
> kcrisman wrote:
>>
>>
>> On Oct 13, 6:05 pm, "ma...@mendelu.cz" <ma...@mendelu.cz> wrote:
>>> Hello all, is there any other possibility how to plot implicit
>>> function than implicitplot?
>>>
>>> I do not like implicitplot too much, since it is in fact countourplot
>>> and it is not easy to set the color (for example).
>>
>> There is not currently any other way to do this, I think.  A colleague
>> of mine has some experimental code to implicit plot the "right" way
>> (by following derivatives around and spot-checking nearby to not miss
>> components, I guess), but doesn't consider it ready for prime time
>> yet.
>
>
> How do you do an implicit plot "right"?  Scipy has tools for numerical
> integration (you mention following derivatives), if that helps.

I think what the user wants is to be able to *work with* contour plots
in the same way one can work with normal plots. E.g., set the color.
Right now they are always black, right? Etc.

>
> A quick google search turns up several references to software:
> http://geomblog.blogspot.com/2008/01/plotting-implicit-functions-bleg.html
>
> The maple help page may help:
> http://www.maplesoft.com/support/help/Maple/view.aspx?path=plots/implicitplot
>
> This issue has come up before on the list (and Josh Kantor gave an
> algorithm and a reference):
> https://groups.google.com/group/sage-devel/browse_thread/thread/6b1d3d0f06db9c6a
>
> More references and algorithms:
> http://www.tangentspace.net/cz/archives/2007/08/implicit-plotting-code-for-mathematica/
>
> Mma also says: ContourPlot initially evaluates f at a grid of equally
> spaced sample points specified by PlotPoints. Then it uses an adaptive
> algorithm to subdivide at most MaxRecursion times to generate smooth
> contours. http://reference.wolfram.com/mathematica/ref/ContourPlot.html
>
> Jason
>
>
> --
> Jason Grout
>
>
> >
>



--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

Jason Grout

unread,
Oct 13, 2009, 11:51:42 PM10/13/09
to sage-s...@googlegroups.com
William Stein wrote:
> On Tue, Oct 13, 2009 at 7:44 PM, Jason Grout
> <jason...@creativetrax.com> wrote:
>> kcrisman wrote:
>>>
>>> On Oct 13, 6:05 pm, "ma...@mendelu.cz" <ma...@mendelu.cz> wrote:
>>>> Hello all, is there any other possibility how to plot implicit
>>>> function than implicitplot?
>>>>
>>>> I do not like implicitplot too much, since it is in fact countourplot
>>>> and it is not easy to set the color (for example).
>>> There is not currently any other way to do this, I think. A colleague
>>> of mine has some experimental code to implicit plot the "right" way
>>> (by following derivatives around and spot-checking nearby to not miss
>>> components, I guess), but doesn't consider it ready for prime time
>>> yet.
>>
>> How do you do an implicit plot "right"? Scipy has tools for numerical
>> integration (you mention following derivatives), if that helps.
>
> I think what the user wants is to be able to *work with* contour plots
> in the same way one can work with normal plots. E.g., set the color.
> Right now they are always black, right? Etc.


Nope; but it's a pretty raw wrapper around the matplotlib functionality.

From the documentation of contour_plot (which is what implicit_plot
really is):

- ``cmap`` -- a colormap (default: ``'gray'``), the name of
a predefined colormap, a list of colors or an instance of a
matplotlib
Colormap. Type: ``import matplotlib.cm;
matplotlib.cm.datad.keys()``
for available colormap names.

We only have one cryptic example, though:

sage: f(x,y) = x^2 + y^2
sage: contour_plot(f, (-2, 2), (-2, 2), contours=2, cmap=[(1,0,0),
(0,1,0), (0,0,1)])

A clearer example would be:

sage: contour_plot(f, (-2, 2), (-2, 2), contours=3,fill=False,
cmap=["red", "green","blue"])


There is no mention of this in implicit_plot docs. However, here is an
example:

implicit_plot(x^2+y^2==1, (x,-2, 2), (y,-2, 2), cmap=["red"])

Mathematica doesn't have an implicitplot anymore, deprecating it for
CountourPlot, which now accepts equations. That's one way to unify the
two concepts.

Jason

--
Jason Grout

ma...@mendelu.cz

unread,
Oct 14, 2009, 12:11:07 AM10/14/09
to sage-support


On 14 říj, 05:51, Jason Grout <jason-s...@creativetrax.com> wrote:
>
> implicit_plot(x^2+y^2==1, (x,-2, 2), (y,-2, 2), cmap=["red"])
>
Thanks, I missed this example.
I tried rgbcolor and color option and then tried blindly various
predefined colormaps.

Robert Marik

Jason Grout

unread,
Oct 14, 2009, 12:19:44 AM10/14/09
to sage-s...@googlegroups.com


I don't think it's anywhere in the docs. I knew to try it because I
knew the code to implicit_plot just passed things on to contour_plot,
and I knew the options to contour_plot.

In short, something like this should either be added to implicit_plot,
or preferably, a better, more consistent option like "color=..." should
be added!

Jason


--
Jason Grout

kcrisman

unread,
Oct 14, 2009, 9:22:02 AM10/14/09
to sage-support
I can't remember which ticket someone just added the labeling of the
contours in contour plot, but presumably this should be even easier to
fix.

- kcrisman

kcrisman

unread,
Oct 14, 2009, 9:23:19 AM10/14/09
to sage-support


On Oct 13, 10:44 pm, Jason Grout <jason-s...@creativetrax.com> wrote:
> kcrisman wrote:
>
> > On Oct 13, 6:05 pm, "ma...@mendelu.cz" <ma...@mendelu.cz> wrote:
> >> Hello all, is there any other possibility how to plot implicit
> >> function than implicitplot?
>
> >> I do not like implicitplot too much, since it is in fact countourplot
> >> and it is not easy to set the color (for example).
>
> > There is not currently any other way to do this, I think.  A colleague
> > of mine has some experimental code to implicit plot the "right" way
> > (by following derivatives around and spot-checking nearby to not miss
> > components, I guess), but doesn't consider it ready for prime time
> > yet.
>
> How do you do an implicit plot "right"?  Scipy has tools for numerical
> integration (you mention following derivatives), if that helps.
>
> A quick google search turns up several references to software:http://geomblog.blogspot.com/2008/01/plotting-implicit-functions-bleg...
>
> The maple help page may help:http://www.maplesoft.com/support/help/Maple/view.aspx?path=plots/impl...
>
> This issue has come up before on the list (and Josh Kantor gave an
> algorithm and a reference):https://groups.google.com/group/sage-devel/browse_thread/thread/6b1d3...
>
> More references and algorithms:http://www.tangentspace.net/cz/archives/2007/08/implicit-plotting-cod...
>
> Mma also says: ContourPlot initially evaluates f at a grid of equally
> spaced sample points specified by PlotPoints. Then it uses an adaptive
> algorithm to subdivide at most MaxRecursion times to generate smooth
> contours.http://reference.wolfram.com/mathematica/ref/ContourPlot.html
>

Yes to all the above.

- kcrisman

Jason Grout

unread,
Oct 14, 2009, 9:45:48 AM10/14/09
to sage-s...@googlegroups.com


I guess we can do a "better" job than matplotlib, as matplotlib does not
have the function to go off of. In a sense, then, you are describing an
adaptive evaluation of the function (at least, that's how mma seems to
do it). I wonder if matplotlib can draw a contour plot from a
non-rectangular grid.

This sounds like an excellent project for a calc 3 student!

Jason

--
Jason Grout

kcrisman

unread,
Oct 14, 2009, 2:57:24 PM10/14/09
to sage-support
This is now #7211.

- kcrisman
Reply all
Reply to author
Forward
0 new messages