ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 07 May 2012 19:48:14 +0200contour plot not working as expectedhttps://ask.sagemath.org/question/8958/contour-plot-not-working-as-expected/Hi all,
I am looking at ways to determine the sign of an angle between a reference vector (a,b) and any other vector(x,y) of the plane. To do so, I have decided to use the determinant of the matrix: [[a b],[x y]] which equals ax-by.
I wanted then to check that the formula works by displaying the plane area which positive and negative signs using the contour_plot.
Here is my question:
Why is the 3rd graph not showing 2 horizontal areas instead of the vertical displayed?
var('x y')
f(x,y,a,b)=(a*y-b*x)/abs(a*y-b*x)
plota1b1=contour_plot(f(x,y,1,1),(-10,10),(-10,10),cmap='jet',colorbar=true)
plota0b1=contour_plot(f(x,y,0,1),(-10,10),(-10,10),cmap='jet',colorbar=true)
plota1b0=contour_plot(f(x,y,1,0),(-10,10),(-10,10),cmap='jet',colorbar=true)
show(plota1b1)
show(plota0b1)
show(plota1b0)
Thanks
Mon, 07 May 2012 04:34:12 +0200https://ask.sagemath.org/question/8958/contour-plot-not-working-as-expected/Answer by sagemb for <p>Hi all,</p>
<p>I am looking at ways to determine the sign of an angle between a reference vector (a,b) and any other vector(x,y) of the plane. To do so, I have decided to use the determinant of the matrix: [[a b],[x y]] which equals ax-by.
I wanted then to check that the formula works by displaying the plane area which positive and negative signs using the contour_plot.</p>
<p>Here is my question:</p>
<p>Why is the 3rd graph not showing 2 horizontal areas instead of the vertical displayed?</p>
<pre><code>var('x y')
f(x,y,a,b)=(a*y-b*x)/abs(a*y-b*x)
plota1b1=contour_plot(f(x,y,1,1),(-10,10),(-10,10),cmap='jet',colorbar=true)
plota0b1=contour_plot(f(x,y,0,1),(-10,10),(-10,10),cmap='jet',colorbar=true)
plota1b0=contour_plot(f(x,y,1,0),(-10,10),(-10,10),cmap='jet',colorbar=true)
show(plota1b1)
show(plota0b1)
show(plota1b0)
</code></pre>
<p>Thanks</p>
https://ask.sagemath.org/question/8958/contour-plot-not-working-as-expected/?answer=13547#post-id-13547Oh, I see. Thank you very much!
BR
MMon, 07 May 2012 10:43:17 +0200https://ask.sagemath.org/question/8958/contour-plot-not-working-as-expected/?answer=13547#post-id-13547Comment by Jason Grout for <p>Oh, I see. Thank you very much!</p>
<p>BR
M</p>
https://ask.sagemath.org/question/8958/contour-plot-not-working-as-expected/?comment=19812#post-id-19812Go ahead and check that as an answer if you feel like it answers your question.Mon, 07 May 2012 19:48:14 +0200https://ask.sagemath.org/question/8958/contour-plot-not-working-as-expected/?comment=19812#post-id-19812Answer by Jason Grout for <p>Hi all,</p>
<p>I am looking at ways to determine the sign of an angle between a reference vector (a,b) and any other vector(x,y) of the plane. To do so, I have decided to use the determinant of the matrix: [[a b],[x y]] which equals ax-by.
I wanted then to check that the formula works by displaying the plane area which positive and negative signs using the contour_plot.</p>
<p>Here is my question:</p>
<p>Why is the 3rd graph not showing 2 horizontal areas instead of the vertical displayed?</p>
<pre><code>var('x y')
f(x,y,a,b)=(a*y-b*x)/abs(a*y-b*x)
plota1b1=contour_plot(f(x,y,1,1),(-10,10),(-10,10),cmap='jet',colorbar=true)
plota0b1=contour_plot(f(x,y,0,1),(-10,10),(-10,10),cmap='jet',colorbar=true)
plota1b0=contour_plot(f(x,y,1,0),(-10,10),(-10,10),cmap='jet',colorbar=true)
show(plota1b1)
show(plota0b1)
show(plota1b0)
</code></pre>
<p>Thanks</p>
https://ask.sagemath.org/question/8958/contour-plot-not-working-as-expected/?answer=13546#post-id-13546The problem is the way you are calling contour plot. Notice that f(x,y,1,0) is y/abs(y). When you are calling contour plot, you aren't specifying which range goes with which variable, so it assumes that the first numeric range (the horizontal axis) goes with the first variable in the expression, which is y.
The solution is to specify explicitly that the horizontal axis corresponds with the x variable, and the vertical axis is for the y variable:
plota1b0=contour_plot(f(x,y,1,0),(x,-10,10),(y,-10,10),cmap='jet',colorbar=true)
See a [live example](http://aleph.sagemath.org/?z=eJydj9EKwjAMRd_3Fb61HRkmH9BvkaRMRKYZXaft36-iDoW96Nu5gZzk3jhak3fFuOZoMxRgEOctt6WTNrs9y7SGZhw0MQn5oNekczw8Bva5R0AOKnWEQFixrBguPHpz7pOBoING4ehTnPuXELeF-LeQBLc_xN-F00nv9t37M-J3rDfdAi9DZeQ%3D)Mon, 07 May 2012 10:32:36 +0200https://ask.sagemath.org/question/8958/contour-plot-not-working-as-expected/?answer=13546#post-id-13546