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.Thu, 10 Nov 2011 22:30:22 +0100Plotting spherical datahttps://ask.sagemath.org/question/8448/plotting-spherical-data/I'd like to know how to plot spherical data in a 3D plot (or to request this feature).
Basically, I have a list of data points in spherical coordinates which represent an antenna pattern. I'd like to plot them and have it look something like this:
http://i.imgur.com/35Lyh.png
My data is only taken every 15 degrees. So I can't do something like this person did:
http://ask.sagemath.org/question/512/plotting-in-3d-in-spherical-coordinates
The reason is that if I create a continuous interpolated function I'd be fabricating data (unless I can re-create a picture like the one above closely).
Ideally a spherical list plot would be ideal, but it seems like the current list plot is only cartesian.
After I successfully get my data plotted, the next steps for my antenna plot viewer would be
1) Make the color map scale set-able (so that multiple antenna plots have colors on the same scale, even if data ranges are different).
2) Make grid-lines visible, like on my picture above.
3) Apply a bicubic interpolation to my data mesh, so it would then look like this (for visual purposes): http://i.imgur.com/U4hPW.png
4) Make the xyz axes visible, like the pic.
All these seem pretty easy, except maybe #2, if anyone knows how that could be done it would be greatly appreciated.
Thanks so much everyone for working on this software. I look forward to this becoming a great tool for engineers and scientists. Mon, 07 Nov 2011 01:49:06 +0100https://ask.sagemath.org/question/8448/plotting-spherical-data/Answer by Giovanni for <p>I'd like to know how to plot spherical data in a 3D plot (or to request this feature).</p>
<p>Basically, I have a list of data points in spherical coordinates which represent an antenna pattern. I'd like to plot them and have it look something like this:</p>
<p><a href="http://i.imgur.com/35Lyh.png">http://i.imgur.com/35Lyh.png</a></p>
<p>My data is only taken every 15 degrees. So I can't do something like this person did:</p>
<p><a href="http://ask.sagemath.org/question/512/plotting-in-3d-in-spherical-coordinates">http://ask.sagemath.org/question/512/...</a></p>
<p>The reason is that if I create a continuous interpolated function I'd be fabricating data (unless I can re-create a picture like the one above closely).</p>
<p>Ideally a spherical list plot would be ideal, but it seems like the current list plot is only cartesian.</p>
<p>After I successfully get my data plotted, the next steps for my antenna plot viewer would be</p>
<p>1) Make the color map scale set-able (so that multiple antenna plots have colors on the same scale, even if data ranges are different).</p>
<p>2) Make grid-lines visible, like on my picture above.</p>
<p>3) Apply a bicubic interpolation to my data mesh, so it would then look like this (for visual purposes): <a href="http://i.imgur.com/U4hPW.png">http://i.imgur.com/U4hPW.png</a></p>
<p>4) Make the xyz axes visible, like the pic.</p>
<p>All these seem pretty easy, except maybe #2, if anyone knows how that could be done it would be greatly appreciated.</p>
<p>Thanks so much everyone for working on this software. I look forward to this becoming a great tool for engineers and scientists. </p>
https://ask.sagemath.org/question/8448/plotting-spherical-data/?answer=12871#post-id-12871I don't think that you can interactively rotate with mplot3d. I'm not an expert anyway. I would say that mayavi2 experimental package fits your bill anyway. I use mayavi2 (outside of Sage) to produce antenna patterns of high quality and works beautifully.
I guess you should proceed as follows:
1) Install mayavi2 package following the instruction at this page http://www.sagemath.org/doc/numerical_sage/installation_linux.html
2) You invoke mayavi2 with something like this (http://www.sagemath.org/doc/numerical_sage/plotting.html)
import numpy
from mayavi.tools import imv
x=numpy.arange(-8,8,.2)
def f(x,y):
r=numpy.sqrt(x**2+y**2)+.01
return numpy.sin(r)/r
imv.surf(x,x,f)
3) The command you want is mesh(). Read the documentation and the examples [here](http://github.enthought.com/mayavi/mayavi/mlab.html) and [here](http://github.enthought.com/mayavi/mayavi/auto/mlab_helper_functions.html#mayavi.mlab.mesh)
hope it helps.
GiovanniWed, 09 Nov 2011 05:40:36 +0100https://ask.sagemath.org/question/8448/plotting-spherical-data/?answer=12871#post-id-12871Answer by Jason Grout for <p>I'd like to know how to plot spherical data in a 3D plot (or to request this feature).</p>
<p>Basically, I have a list of data points in spherical coordinates which represent an antenna pattern. I'd like to plot them and have it look something like this:</p>
<p><a href="http://i.imgur.com/35Lyh.png">http://i.imgur.com/35Lyh.png</a></p>
<p>My data is only taken every 15 degrees. So I can't do something like this person did:</p>
<p><a href="http://ask.sagemath.org/question/512/plotting-in-3d-in-spherical-coordinates">http://ask.sagemath.org/question/512/...</a></p>
<p>The reason is that if I create a continuous interpolated function I'd be fabricating data (unless I can re-create a picture like the one above closely).</p>
<p>Ideally a spherical list plot would be ideal, but it seems like the current list plot is only cartesian.</p>
<p>After I successfully get my data plotted, the next steps for my antenna plot viewer would be</p>
<p>1) Make the color map scale set-able (so that multiple antenna plots have colors on the same scale, even if data ranges are different).</p>
<p>2) Make grid-lines visible, like on my picture above.</p>
<p>3) Apply a bicubic interpolation to my data mesh, so it would then look like this (for visual purposes): <a href="http://i.imgur.com/U4hPW.png">http://i.imgur.com/U4hPW.png</a></p>
<p>4) Make the xyz axes visible, like the pic.</p>
<p>All these seem pretty easy, except maybe #2, if anyone knows how that could be done it would be greatly appreciated.</p>
<p>Thanks so much everyone for working on this software. I look forward to this becoming a great tool for engineers and scientists. </p>
https://ask.sagemath.org/question/8448/plotting-spherical-data/?answer=11673#post-id-11673You could do the spherical transformation yourself to do a spherical list plot. See http://sagenb.org/home/pub/3616/ for an example, using the radius, azimuth, inclination convention for spherical coordinates.Tue, 08 Nov 2011 20:22:02 +0100https://ask.sagemath.org/question/8448/plotting-spherical-data/?answer=11673#post-id-11673Comment by Jason for <p>You could do the spherical transformation yourself to do a spherical list plot. See <a href="http://sagenb.org/home/pub/3616/">http://sagenb.org/home/pub/3616/</a> for an example, using the radius, azimuth, inclination convention for spherical coordinates.</p>
https://ask.sagemath.org/question/8448/plotting-spherical-data/?comment=20927#post-id-20927I was using the list plot function. The points function plots correctly, however it doesn't give me a surface. Here's some example data and code: http://sagenb.org/home/pub/3646/Thu, 10 Nov 2011 22:30:22 +0100https://ask.sagemath.org/question/8448/plotting-spherical-data/?comment=20927#post-id-20927Comment by Jason for <p>You could do the spherical transformation yourself to do a spherical list plot. See <a href="http://sagenb.org/home/pub/3616/">http://sagenb.org/home/pub/3616/</a> for an example, using the radius, azimuth, inclination convention for spherical coordinates.</p>
https://ask.sagemath.org/question/8448/plotting-spherical-data/?comment=20946#post-id-20946Thanks. For transforming the data before using the function, an error occurs because I have multiple data points with the same xy coordinate (looking at my pictures above you can see both hemispheres are symmetrical). When I sort my list of xyz tuples into the upper and lower hemispheres, it doesn't seem to plot correctly. Another problem is that in the corners of the graph there is a flat plane until the data starts. Putting two of these together would have a square sticking out between the two hemispheres. Also, one of my initial problems was usage of the list plot 3d function. Where can I give constructive feedback on it?Tue, 08 Nov 2011 23:06:45 +0100https://ask.sagemath.org/question/8448/plotting-spherical-data/?comment=20946#post-id-20946Comment by Jason Grout for <p>You could do the spherical transformation yourself to do a spherical list plot. See <a href="http://sagenb.org/home/pub/3616/">http://sagenb.org/home/pub/3616/</a> for an example, using the radius, azimuth, inclination convention for spherical coordinates.</p>
https://ask.sagemath.org/question/8448/plotting-spherical-data/?comment=20942#post-id-20942Are you using the points command to plot the data points, like in the above example? That shouldn't care about having the same xy coordinates. How would you use the lisplot 3d function to plot a list of points? Here would be a good place to give constructive feedback. The sage-support mailing list might be an even better place. Or the best place would be to submit a patch to the bug tracker: http://trac.sagemath.org/sage_trac/Wed, 09 Nov 2011 22:26:25 +0100https://ask.sagemath.org/question/8448/plotting-spherical-data/?comment=20942#post-id-20942Answer by Giovanni for <p>I'd like to know how to plot spherical data in a 3D plot (or to request this feature).</p>
<p>Basically, I have a list of data points in spherical coordinates which represent an antenna pattern. I'd like to plot them and have it look something like this:</p>
<p><a href="http://i.imgur.com/35Lyh.png">http://i.imgur.com/35Lyh.png</a></p>
<p>My data is only taken every 15 degrees. So I can't do something like this person did:</p>
<p><a href="http://ask.sagemath.org/question/512/plotting-in-3d-in-spherical-coordinates">http://ask.sagemath.org/question/512/...</a></p>
<p>The reason is that if I create a continuous interpolated function I'd be fabricating data (unless I can re-create a picture like the one above closely).</p>
<p>Ideally a spherical list plot would be ideal, but it seems like the current list plot is only cartesian.</p>
<p>After I successfully get my data plotted, the next steps for my antenna plot viewer would be</p>
<p>1) Make the color map scale set-able (so that multiple antenna plots have colors on the same scale, even if data ranges are different).</p>
<p>2) Make grid-lines visible, like on my picture above.</p>
<p>3) Apply a bicubic interpolation to my data mesh, so it would then look like this (for visual purposes): <a href="http://i.imgur.com/U4hPW.png">http://i.imgur.com/U4hPW.png</a></p>
<p>4) Make the xyz axes visible, like the pic.</p>
<p>All these seem pretty easy, except maybe #2, if anyone knows how that could be done it would be greatly appreciated.</p>
<p>Thanks so much everyone for working on this software. I look forward to this becoming a great tool for engineers and scientists. </p>
https://ask.sagemath.org/question/8448/plotting-spherical-data/?answer=12870#post-id-12870I do not think that you can get all of that directly with sage.
A viable option would be to call mplot3d (plot_surface) from matplotlib, which is easily done in Sage. This way you can get point 1,2,4 even if the axis are displayed in a different way, and I think also point 3, but i am not sure about that. All the references are [here](http://matplotlib.sourceforge.net/mpl_toolkits/mplot3d/tutorial.html#surface-plots).
If you need some kind of interpolation, I suggest you employ scipy.interpolate module. You can get many different types of N dimensional interpolation.
Tue, 08 Nov 2011 11:13:42 +0100https://ask.sagemath.org/question/8448/plotting-spherical-data/?answer=12870#post-id-12870Comment by Jason for <p>I do not think that you can get all of that directly with sage. </p>
<p>A viable option would be to call mplot3d (plot_surface) from matplotlib, which is easily done in Sage. This way you can get point 1,2,4 even if the axis are displayed in a different way, and I think also point 3, but i am not sure about that. All the references are <a href="http://matplotlib.sourceforge.net/mpl_toolkits/mplot3d/tutorial.html#surface-plots">here</a>.</p>
<p>If you need some kind of interpolation, I suggest you employ scipy.interpolate module. You can get many different types of N dimensional interpolation.</p>
https://ask.sagemath.org/question/8448/plotting-spherical-data/?comment=20947#post-id-20947Thanks, I'll try that out. Is this incompatible with JMol? Having a rotatable 3D plot is also a requirement for me.Tue, 08 Nov 2011 16:34:48 +0100https://ask.sagemath.org/question/8448/plotting-spherical-data/?comment=20947#post-id-20947