Ask Your Question
2

multiple region_plots in one plot

asked 2012-03-15 09:11:55 +0100

god.one gravatar image

Hi, I want to plot two region_plots into one plot. The idea is if you use different colors for the inequalities you can see how the regions change. A minimal example:

var('x,y')
plot1=region_plot(x<y,(x,0,1),(y,0,1),incol='red')
plot2=region_plot(2*x<y,(x,0,1),(y,0,1),incol='blue')
show(plot2+plot1)

I do not know how to manage this, since zorder or opacity are not working for region_plot. Does anybody know how to make this work (by the way I use sagenb.org)? Thanks in advance

edit retag flag offensive close merge delete

Comments

Just for reference, `plot1+plot2` gives a different (also not so useful) plot.

kcrisman gravatar imagekcrisman ( 2012-03-15 09:39:42 +0100 )edit

@kcrisman : ok, but could you please explain what you mean with <not so="" useful="" plot="">?

god.one gravatar imagegod.one ( 2012-03-15 09:43:21 +0100 )edit
1

By not-so-useful I just mean that it seems to have a similar problem to your original one, but with the opposite region "on top". It was just a comment, not an answer of any kind!

kcrisman gravatar imagekcrisman ( 2012-03-15 09:50:33 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
4

answered 2012-03-16 12:58:07 +0100

niles gravatar image

updated 2012-03-16 13:00:43 +0100

The problem is that a region_plot is really just a contour plot with exactly two colored regions. The "inside" color is determined by incolor, and the "outside" is determined by outcolor. Now here's the key: outcolor is white by default, so you might think that the outside of the region is transparent. But it's not. That explains why you only see one of the two plots -- the top one is completely opaque, thus covering the bottom one. This also explains why you get different results when you sum the two plots in different orders -- this changes which one is on top.

Now here's a fix: just use contour_plot directly. To do this, define a function which will separate the regions you're interested in. For example:

def sep(x,y):
    if 2*x < y:
        return 1
    if x < y and y <= 2*x:
        return 0
    if y <= x:
        return -1

Now make the contour plot, choosing contour lines between your separate outputs, and listing the colors you want:

contour_plot(sep, (x,0,2), (y,0,2), plot_points=400, contours=[-.5,.5], cmap=['white','red','blue'])

image description

Also note that contour_plot will probably work pretty well without you explicitly specifying the contours or the colors, if you don't want to worry about that step.

edit flag offensive delete link more

Comments

Ah, of course! I don't know why I didn't see that, having worked on this code in the past... Great work.

kcrisman gravatar imagekcrisman ( 2012-03-16 21:48:26 +0100 )edit

So do you think this is worth a trac ticket? I feel like we would really want the original thing to work. But I'm not sure exactly how to do this without removing the 'white' business, which would make the graphics look weird, if I recall correctly.

kcrisman gravatar imagekcrisman ( 2012-03-16 21:49:25 +0100 )edit

this could be a feature request: allow region_plot to color multiple regions. But I don't think I'm motivated enough to open a ticket for it.

niles gravatar imageniles ( 2012-03-17 15:28:27 +0100 )edit

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: 2012-03-15 09:11:55 +0100

Seen: 1,209 times

Last updated: Mar 16 '12