Opened 12 years ago

Closed 12 years ago

#1862 closed defect (fixed)

[with patch, positive review] implement at least some sort of useful rudimentary implicit 2d plotting function

Reported by: was Owned by: was
Priority: major Milestone: sage-2.10.4
Component: graphics Keywords:
Cc: harald.schilly@… Merged in:
Authors: Reviewers:
Report Upstream: Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by was)

On Jan 19, 2008 12:44 AM, Dagda <> wrote:
> 
> Hi,
> I was wondering if there was a way to plot relations implicitly, in 2D
> and/or 3D. A simple example would be to plot a circle with something
> like the following:
> 
> plot_implicit(x^2+y^2=1)

Here's how do this sort of thing using contour_plot in sage right now.
(Note -- for efficiency reasons, you definitely want to only plot a Python
function -- i.e., lambda -- at present.  This will change soon.)

First, define this function in Sage:

def implicit_plot(f, x_range, y_range, plot_points=100):
      return contour_plot(f, x_range, y_range, fill=False, contours=1, plot_points=plot_points)

Then use it:

sage: implicit_plot(lambda x,y: x^2 + y^2 - 1, (-2,2), (-2,2))
sage: implicit_plot(lambda x,y: x^3 + x*y^2 - 1, (-2,2), (-2,2))
sage: implicit_plot(lambda x,y: (x-y^2)*(y-x^3), (-2,2), (-2,2))

The input should be a function f of two variables, and implicit_plot as I've
defined it above graphs f(x,y) == 0 in the given region.

This could be turned into a first version of a genuine implicit plot at some point. 

Josh Kantor is also looking into some other more sophisticated related
approaches.    It would be good to understand precisely how Sage's
contour_plot function works (it builds mostly on matplotlib's functions)....

William

Attachments (2)

implicit-plot.patch (13.5 KB) - added by cwitty 12 years ago.
1862.patch (13.0 KB) - added by mhansen 12 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 Changed 12 years ago by was

  • Description modified (diff)

comment:2 Changed 12 years ago by schilly

  • Cc harald.schilly@… added

comment:3 Changed 12 years ago by mabshoff

  • Summary changed from implement at least some sort of useful rudimentary implicit 2d plotting function to [with bundle] implement at least some sort of useful rudimentary implicit 2d plotting functio

Robert Bradshaw's bundle at #1938 includes this functionality.

Cheers,

Michael

comment:4 Changed 12 years ago by was

Robert Bradshaw's bundle at #1938 includes this functionality.

I just refereed that patch and I can't find any implicit_plot functionality in it...

comment:5 Changed 12 years ago by mhansen

  • Summary changed from [with bundle] implement at least some sort of useful rudimentary implicit 2d plotting functio to implement at least some sort of useful rudimentary implicit 2d plotting functio

Changed 12 years ago by cwitty

comment:6 Changed 12 years ago by cwitty

  • Summary changed from implement at least some sort of useful rudimentary implicit 2d plotting functio to [with patch, needs review] implement at least some sort of useful rudimentary implicit 2d plotting function

This patch adds implicit_plot (based on contour_plot, as William suggests). It also fixes some broken code (and adds doctests) elsewhere in plot.py .

comment:7 Changed 12 years ago by wdj

Some problems:

sage: x,y=var("x,y")
sage: implicit_plot(x^2+y^2-1,(-1,1),(-1,1))

takes a very long time (in fact, I tried to kill it using ctl-c repeatedly and had a hard time). On the other hand,

sage: f = lambda x,y: x^2+y^2-1
sage: implicit_plot(f,(-1,1),(-1,1))

is almost instantaneous. Can this be fixed or at least documented?

comment:8 Changed 12 years ago by was

Can this be fixed or at least documented?

This should be trivial to fix by changing implicit_plot to call fast_float. In fact, then the relevant part of your first example would be 10 times faster than the second.

comment:9 Changed 12 years ago by was

  • Milestone changed from sage-2.11 to sage-2.10.4

Changed 12 years ago by mhansen

comment:10 Changed 12 years ago by mhansen

  • Summary changed from [with patch, needs review] implement at least some sort of useful rudimentary implicit 2d plotting function to [with patch, positive review] implement at least some sort of useful rudimentary implicit 2d plotting function

I've put up a version of the patch ( 1862.patch ) rebased against 2.10.4.alpha0. That's the one that should be applied. Other than that, looks good to me.

comment:11 Changed 12 years ago by mabshoff

  • Resolution set to fixed
  • Status changed from new to closed

Merged 1862.patch in Sage 2.10.4.rc0

Note: See TracTickets for help on using tickets.