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.Mon, 08 Apr 2019 15:27:27 -0500Graphing Complex Functions 3D (x,y,i axes) Instead Of Color-Coded 2D (x,i)http://ask.sagemath.org/question/10368/graphing-complex-functions-3d-xyi-axes-instead-of-color-coded-2d-xi/Following [this guide to Sage][1]: and using [Sage Online][2] produced the following graphs:
![enter image description here][3]
![enter image description here][4]
It would be nice to see it in 3D instead of merely color coded. The y-axis is coming out of the picture toward us and instead of seeing the 3D surface (in x,y,i coordinates) we see a color-graph on the x-i plane.
You can do what I wish [using Maple:](http://math.stackexchange.com/questions/448397/graphing-compex-functions-3d-x-y-i-axes-instead-of-color-coded-sage/448410?noredirect=1#448410)
[1]: http://www.sagemath.org/doc/reference/plotting/sage/plot/complex_plot.html
[2]: http://www.sagenb.org/
[3]: http://i.stack.imgur.com/gw8Aj.png
[4]: http://i.stack.imgur.com/NYP76.jpgSat, 20 Jul 2013 13:50:24 -0500http://ask.sagemath.org/question/10368/graphing-complex-functions-3d-xyi-axes-instead-of-color-coded-2d-xi/Answer by slelievre for <p>Following <a href="http://www.sagemath.org/doc/reference/plotting/sage/plot/complex_plot.html">this guide to Sage</a>: and using <a href="http://www.sagenb.org/">Sage Online</a> produced the following graphs: </p>
<p><img alt="enter image description here" src="http://i.stack.imgur.com/gw8Aj.png"></p>
<p><img alt="enter image description here" src="http://i.stack.imgur.com/NYP76.jpg"></p>
<p>It would be nice to see it in 3D instead of merely color coded. The y-axis is coming out of the picture toward us and instead of seeing the 3D surface (in x,y,i coordinates) we see a color-graph on the x-i plane. </p>
<p>You can do what I wish <a href="http://math.stackexchange.com/questions/448397/graphing-compex-functions-3d-x-y-i-axes-instead-of-color-coded-sage/448410?noredirect=1#448410">using Maple:</a></p>
http://ask.sagemath.org/question/10368/graphing-complex-functions-3d-xyi-axes-instead-of-color-coded-2d-xi/?answer=46055#post-id-46055Iterating on @FrédéricC's answer...
In the following we
- increase the number of plot points to improve the resolution of the image,
- use `RDF` and `CDF`: "real double field", "complex double field" -- floating-point real and complex numbers,
- avoid Sage's "symbolic variables" and "symbolic ring" throughout.
Doing this, the spike however reaches higher and higher values, so it becomes
necessary to truncate the z values.
Pick a colormap and define $\tau = 2\pi$.
sage: cm = colormaps.jet
sage: tau = 2 * RDF.pi()
Define `f`:
sage: def f(x, y):
....: z = CDF(x, y)
....: return (z - 2) / (z + 3)**2
Define `f_abs` (modulus of `f`):
sage: f_abs = lambda x, y: f(x, y).abs()
Define truncation:
sage: trunc = lambda x, t: x if x.abs() < t else RDF.nan()
Pick a bound to truncate:
sage: zbound = 8
Define `f_abs_trunc` as `f_abs` truncated to the chosen bound.
sage: f_abs_trunc = lambda x, y: trunc(f_abs(x, y), zbound)
Define `f_arg_color` as the coloring for the argument of f:
sage: f_arg_color = lambda x, y: f(x, y).arg() / tau + RDF(0.5)
Compute the plot:
sage: p = plot3d(f_abs_trunc, (-4, 4), (-4, 4), color=(f_arg_color, cm), plot_points=200)
Show the plot (choose `viewer='threejs'` or `viewer='jmol'` or `viewer='tachyon'`):
sage: p.show(viewer='threejs')
Increasing `plot_points` further makes a nicer plot while also increasing the time to show the plot.
Try for example `plot_points=400` or even `plot_points=800`.
One can also increase `zbound` to see more of the spike (try for example `zbound=1e2` or `zbound=2e5`).
Or plot `f_abs` instead of `f_abs_trunc` to avoid truncation altogether.Mon, 08 Apr 2019 15:27:27 -0500http://ask.sagemath.org/question/10368/graphing-complex-functions-3d-xyi-axes-instead-of-color-coded-2d-xi/?answer=46055#post-id-46055Answer by FrédéricC for <p>Following <a href="http://www.sagemath.org/doc/reference/plotting/sage/plot/complex_plot.html">this guide to Sage</a>: and using <a href="http://www.sagenb.org/">Sage Online</a> produced the following graphs: </p>
<p><img alt="enter image description here" src="http://i.stack.imgur.com/gw8Aj.png"></p>
<p><img alt="enter image description here" src="http://i.stack.imgur.com/NYP76.jpg"></p>
<p>It would be nice to see it in 3D instead of merely color coded. The y-axis is coming out of the picture toward us and instead of seeing the 3D surface (in x,y,i coordinates) we see a color-graph on the x-i plane. </p>
<p>You can do what I wish <a href="http://math.stackexchange.com/questions/448397/graphing-compex-functions-3d-x-y-i-axes-instead-of-color-coded-sage/448410?noredirect=1#448410">using Maple:</a></p>
http://ask.sagemath.org/question/10368/graphing-complex-functions-3d-xyi-axes-instead-of-color-coded-2d-xi/?answer=46041#post-id-46041Some approximation :
var('x,y')
cm = colormaps.jet
pi2 = 2 * pi.n()
def f(x, y):
z = x + I * y
return (z-2)/(z+3)**2
def cf(x, y):
return f(x, y).n().arg() / pi2 + 0.5
plot3d(lambda x, y: f(x, y).n().abs(), (x,-4,4), (y,-4,4), color=(cf, cm))Sun, 07 Apr 2019 12:12:23 -0500http://ask.sagemath.org/question/10368/graphing-complex-functions-3d-xyi-axes-instead-of-color-coded-2d-xi/?answer=46041#post-id-46041Answer by calc314 for <p>Following <a href="http://www.sagemath.org/doc/reference/plotting/sage/plot/complex_plot.html">this guide to Sage</a>: and using <a href="http://www.sagenb.org/">Sage Online</a> produced the following graphs: </p>
<p><img alt="enter image description here" src="http://i.stack.imgur.com/gw8Aj.png"></p>
<p><img alt="enter image description here" src="http://i.stack.imgur.com/NYP76.jpg"></p>
<p>It would be nice to see it in 3D instead of merely color coded. The y-axis is coming out of the picture toward us and instead of seeing the 3D surface (in x,y,i coordinates) we see a color-graph on the x-i plane. </p>
<p>You can do what I wish <a href="http://math.stackexchange.com/questions/448397/graphing-compex-functions-3d-x-y-i-axes-instead-of-color-coded-sage/448410?noredirect=1#448410">using Maple:</a></p>
http://ask.sagemath.org/question/10368/graphing-complex-functions-3d-xyi-axes-instead-of-color-coded-2d-xi/?answer=15259#post-id-15259One approach would be to use `plot3d`. For example,
var('x,y')
plot3d(lambda x,y: norm(1/(((x+i*y)-3)*((x+y*i)+2))),(x,-4,4),(y,-4,4))
gives
![image description](/upfiles/1374370159956205.jpg)
I've not been able to get the coloring that you'd probably like, but this does give the 3d plot rather than the 2d plot you were getting.
Sat, 20 Jul 2013 15:31:16 -0500http://ask.sagemath.org/question/10368/graphing-complex-functions-3d-xyi-axes-instead-of-color-coded-2d-xi/?answer=15259#post-id-15259