ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 16 Mar 2018 10:21:19 -0500Fill colors with two contour plotshttp://ask.sagemath.org/question/41457/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 !Fri, 09 Mar 2018 15:30:28 -0600http://ask.sagemath.org/question/41457/fill-colors-with-two-contour-plots/Comment by slelievre for <p>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:</p>
<pre><code>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);
</code></pre>
<p>The problem is that the resulting picture only shows the filling colors of the second plot.</p>
<p>How do I get a picture with each zone (from both plots) in a different color ? some kind of transparency ?</p>
<p>Sorry if my question is trivial,</p>
<p>Thanks !</p>
http://ask.sagemath.org/question/41457/fill-colors-with-two-contour-plots/?comment=41584#post-id-41584See [Sage Trac ticket #9491: contour plot does not handle transparency](https://trac.sagemath.org/ticket/9491).Fri, 16 Mar 2018 10:21:19 -0500http://ask.sagemath.org/question/41457/fill-colors-with-two-contour-plots/?comment=41584#post-id-41584Comment by user111 for <p>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:</p>
<pre><code>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);
</code></pre>
<p>The problem is that the resulting picture only shows the filling colors of the second plot.</p>
<p>How do I get a picture with each zone (from both plots) in a different color ? some kind of transparency ?</p>
<p>Sorry if my question is trivial,</p>
<p>Thanks !</p>
http://ask.sagemath.org/question/41457/fill-colors-with-two-contour-plots/?comment=41472#post-id-41472for instance: A = x; B = y;Sat, 10 Mar 2018 05:15:37 -0600http://ask.sagemath.org/question/41457/fill-colors-with-two-contour-plots/?comment=41472#post-id-41472Comment by tmonteil for <p>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:</p>
<pre><code>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);
</code></pre>
<p>The problem is that the resulting picture only shows the filling colors of the second plot.</p>
<p>How do I get a picture with each zone (from both plots) in a different color ? some kind of transparency ?</p>
<p>Sorry if my question is trivial,</p>
<p>Thanks !</p>
http://ask.sagemath.org/question/41457/fill-colors-with-two-contour-plots/?comment=41469#post-id-41469Could you please provide the code for `A` and `B`.Sat, 10 Mar 2018 05:03:55 -0600http://ask.sagemath.org/question/41457/fill-colors-with-two-contour-plots/?comment=41469#post-id-41469Answer by Sébastien for <p>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:</p>
<pre><code>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);
</code></pre>
<p>The problem is that the resulting picture only shows the filling colors of the second plot.</p>
<p>How do I get a picture with each zone (from both plots) in a different color ? some kind of transparency ?</p>
<p>Sorry if my question is trivial,</p>
<p>Thanks !</p>
http://ask.sagemath.org/question/41457/fill-colors-with-two-contour-plots/?answer=41574#post-id-41574In 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
![image description](/upfiles/15211513166851653.png)
Note that the color output is not commutative (!):
sage: C+B+A
![image description](/upfiles/15211513259253121.png)Thu, 15 Mar 2018 17:19:16 -0500http://ask.sagemath.org/question/41457/fill-colors-with-two-contour-plots/?answer=41574#post-id-41574Comment by user111 for <p>In Sage, there is a argument called <code>alpha</code> which allows to define transparency. For example, it is documented in <code>line2d?</code> and in <code>text?</code> which says "<em><code>alpha</code> - A float (0.0 transparent through 1.0 opaque)</em>". Unfortunately, <code>contour_plot</code> does no allow to use <code>alpha</code> as input.</p>
<p>You may use <code>region_plot</code> instead which allows to use the argument <code>alpha</code> even if not documented:</p>
<pre><code>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
</code></pre>
<p><img alt="image description" src="/upfiles/15211513166851653.png"></p>
<p>Note that the color output is not commutative (!):</p>
<pre><code>sage: C+B+A
</code></pre>
<p><img alt="image description" src="/upfiles/15211513259253121.png"></p>
http://ask.sagemath.org/question/41457/fill-colors-with-two-contour-plots/?comment=41581#post-id-41581Wonderful ! Thank you (sorry that I can't upvote).Fri, 16 Mar 2018 07:34:22 -0500http://ask.sagemath.org/question/41457/fill-colors-with-two-contour-plots/?comment=41581#post-id-41581