# 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

Could you please provide the code for A and B.

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