Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plot_region function #2770

Closed
jasongrout opened this issue Apr 2, 2008 · 13 comments
Closed

plot_region function #2770

jasongrout opened this issue Apr 2, 2008 · 13 comments

Comments

@jasongrout
Copy link
Member

It would be great to have a plot_region function which would plot a region where a system of equations/inequalities were true.

Here is an initial version:

def plot_region(funcs, var1_range, var2_range, plot_points=400, **kwds):
    if not isinstance(funcs, (list, tuple)):
        funcs = [funcs]
    hvar, hmin, hmax = var1_range
    vvar, vmin, vmax = var2_range
    funcs = prod([f._fast_float_("%r"%hvar, "%r"%vvar) for f in funcs])
    return contour_plot(funcs, var1_range, var2_range, plot_points=plot_points,**kwds)

This uses an idea from cwitty (to use contour_plot) and the patch from #2768. A screenshot is attached below.

Component: graphics

Issue created by migration from https://trac.sagemath.org/ticket/2770

@sagetrac-abergeron
Copy link
Mannequin

sagetrac-abergeron mannequin commented Dec 28, 2008

comment:1

Attachment: plot-region.png

If you want to try out part1, you need to apply the patch at #4884. At the moment it support only one function.

Multiple function support is coming in part2.

@sagetrac-abergeron
Copy link
Mannequin

sagetrac-abergeron mannequin commented Dec 28, 2008

comment:2

Attachment: trac_2770_part2.patch.gz

Now it is complete, apply both patches and the patch at #4884 to test.

The example in the screenshot should work, but is rather ugly at the default plot_points setting, try at plot_points=200 to see it looking good.

@sagetrac-abergeron
Copy link
Mannequin

sagetrac-abergeron mannequin commented Dec 29, 2008

comment:3

Since there is heavy discussion at #4884 I will wait until that settles to update this patch to work with whatever is decided upon.

@sagetrac-abergeron sagetrac-abergeron mannequin changed the title plot_region function [with patch; don't review yet] plot_region function Dec 29, 2008
@sagetrac-abergeron
Copy link
Mannequin

sagetrac-abergeron mannequin commented Dec 30, 2008

comment:4

#4884 is settled

@sagetrac-abergeron sagetrac-abergeron mannequin changed the title [with patch; don't review yet] plot_region function plot_region function Dec 30, 2008
@wdjoyner
Copy link

comment:5

This has some odd behavior which I hope the author could please comment on:

This looks good:

sage: P1 = region_plot(cos(x^2+y^2) <= 0, (-3, 3), (-3, 3), incol='green', bordercol='red')
sage: show(P1)

This looks very odd (wrong but maybe the algorithm just needs more points?):

sage: P2 = region_plot(cos(x^2+y^2) <= 0, (-30, 30), (-30, 30), incol='green', bordercol='red')
sage: show(P2)

This looks plain wrong (and I think we have provided enough points:-):

sage: P3 = region_plot(cos(x^2+y^2) <= 0, (-30, 30), (-30, 30), incol='green', bordercol='red', plot_points=1000)
sage: show(P3)

@wdjoyner
Copy link

comment:6

Means to add to the review above:

If you first apply the first patch at #4884 (but not the second), then the two patches above apply cleanly to 3.2.2.

@sagetrac-abergeron
Copy link
Mannequin

sagetrac-abergeron mannequin commented Dec 30, 2008

comment:7

The first very wrong case is really because there is not enough data to interpolate properly.

In the second case it's too much of a good thing. There is too much data and every insignificant contour line gets plotted and since they have a minimum width you get a red picture.

For this example, plot_points=400 looks much more reasonable.

@wdjoyner
Copy link

comment:8

Okay, thanks for that explanation. This is a useful patch.

My impression is that if it can't be easily fixed, then at least it should be documented how to adjust the parameters to get proper behaviour. I'm guessing that the people who will use this patch are students and teachers, so the more detailed examples the better:-) Does this seem reasonable?

With that's I'd be prepared to give it a positive review.

Other cool examples you could include:

sage: region_plot(x*(x-1)*(x+1)+y^2<0, (-3, 2), (-3, 3), incol='lightblue', bordercol='gray', plot_points=400)
sage: region_plot([x*(x-1)*(x+1)+y^2<0, x>-1], (-3, 2), (-3, 3), incol='lightblue', bordercol='gray', plot_points=400)

And one similar to Jason's:

sage: P = region_plot([x^2+y^2<4, x>-1], (-2, 2), (-2, 2), incol='lightblue', bordercol='gray', plot_points=400)
sage: P.show(aspect_ratio=1)

(I know you have

region_plot([x^2+y^2<1, x<y], (-2,2), (-2,2)) 

but it looks odd without the aspect ratio set.)

Do these seem reasonable Arnaud?

@sagetrac-abergeron
Copy link
Mannequin

sagetrac-abergeron mannequin commented Dec 30, 2008

Attachment: trac_2770_part2.1.patch.gz

@sagetrac-abergeron
Copy link
Mannequin

sagetrac-abergeron mannequin commented Dec 30, 2008

comment:9

I agree with more examples. I just did not have a huge inspiration for them.

The last patch adds your suggested examples.

@wdjoyner
Copy link

comment:10

The patches applied fine but the test timed out on my machine (amd64 ubuntu 8.10). So, positive review for the patch but I could not do the test using sage -t. (The examples seemed to work okay though.)

@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented Jan 12, 2009

This is a slightly rebased version of Arnaud Bergeron's patch

@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented Jan 12, 2009

comment:11

Attachment: trac_2770_part1.patch.gz

Merged all three patches in Sage 3.3.alpha0

@sagetrac-mabshoff sagetrac-mabshoff mannequin closed this as completed Jan 12, 2009
@sagetrac-mabshoff sagetrac-mabshoff mannequin removed this from the sage-3.4.1 milestone Jan 12, 2009
@sagetrac-mabshoff sagetrac-mabshoff mannequin added this to the sage-3.3 milestone Jan 12, 2009
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants