Ask Your Question

# Fill colors with two contour plots

Assume I have two contour plots, of functions A and B, say, depending on x and y, with one level curve on each plot. There are two different zones in each plot, filled with two colors, like in the following:

Gr=Graphics();
Gr += contour_plot(A,(x,0,10),(y,0,10),contours=1,cmap=['white', 'red']);
Gr += contour_plot(B,(x,0,10),(y,0,10),contours=1,cmap=['yellow', 'blue']);
show(Gr);


The problem is that the resulting picture only shows the filling colors of the second plot.

How do I get a picture with each zone (from both plots) in a different color ? some kind of transparency ?

Sorry if my question is trivial,

Thanks !

edit retag close merge delete

## Comments

Could you please provide the code for A and B.

( 2018-03-10 05:03:55 -0500 )edit

for instance: A = x; B = y;

( 2018-03-10 05:15:37 -0500 )edit
( 2018-03-16 10:21:19 -0500 )edit

## 1 answer

Sort by » oldest newest most voted

In Sage, there is a argument called alpha which allows to define transparency. For example, it is documented in line2d? and in text? which says "alpha - A float (0.0 transparent through 1.0 opaque)". Unfortunately, contour_plot does no allow to use alpha as input.

You may use region_plot instead which allows to use the argument alpha even if not documented:

sage: x,y = var('x,y')
sage: A = region_plot(x^2 + y^2 < 1, (x,-1,2), (y,-1,2), incol='blue', alpha=.4)
sage: B = region_plot((x-1)^2 + y^2 < 1, (x,-1,2), (y,-1,2), incol='red', alpha=.4)
sage: C = region_plot((x-.5)^2 + (y-.86)^2 < 1, (x,-1,2), (y,-1,2), incol='green', alpha=.4)
sage: A+B+C


Note that the color output is not commutative (!):

sage: C+B+A


more

## Comments

Wonderful ! Thank you (sorry that I can't upvote).

( 2018-03-16 07:34:22 -0500 )edit

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

Asked: 2018-03-09 15:30:28 -0500

Seen: 180 times

Last updated: Mar 15 '18