Ask Your Question

Giovanni's profile - activity

2017-02-09 18:08:25 +0200 received badge  Famous Question (source)
2016-09-08 20:08:34 +0200 received badge  Taxonomist
2015-06-04 17:38:21 +0200 received badge  Notable Question (source)
2015-06-04 17:38:21 +0200 received badge  Popular Question (source)
2014-05-23 16:52:22 +0200 received badge  Famous Question (source)
2013-05-13 09:19:45 +0200 received badge  Famous Question (source)
2012-12-03 13:19:51 +0200 received badge  Notable Question (source)
2012-08-16 07:38:08 +0200 received badge  Notable Question (source)
2012-04-18 21:32:41 +0200 received badge  Popular Question (source)
2012-04-10 17:35:00 +0200 received badge  Popular Question (source)
2011-12-22 12:39:31 +0200 received badge  Nice Question (source)
2011-12-16 03:16:55 +0200 asked a question "Evaluate All" keyboard shortcut

Is there any keyboard shortcut for the notebook command "Evaluate All"? Or in alternative could it be assigned somehow? Thanks a lot!

2011-11-09 06:28:39 +0200 received badge  Citizen Patrol (source)
2011-11-09 06:00:08 +0200 received badge  Nice Question (source)
2011-11-09 05:40:36 +0200 answered a question Plotting spherical data

I 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

2) You invoke mayavi2 with something like this (

import numpy
from import imv
def f(x,y):
    return numpy.sin(r)/r,x,f)

3) The command you want is mesh(). Read the documentation and the examples here and here

hope it helps.


2011-11-08 23:10:01 +0200 received badge  Teacher (source)
2011-11-08 11:14:46 +0200 marked best answer 2D interpolating function from numpy arrays to spherical-plot3d

It's because your f function above is returning a numpy array, rather than a number.

sage: f(1,2)
array([[ 0.45712591]])
sage: f(1,2)[0,0]

So you need to extract that number out. You did it in your last example above. Here's another way:

spherical_plot3d(lambda x,y: f(x,y)[0,0],(x,0,2*pi),(y,0,pi))

Here is yet another way, since numpy arrays with a single value like that can be cast to floats.

spherical_plot3d(lambda x,y: float(f(x,y)),(x,0,2*pi),(y,0,pi))
2011-11-08 11:13:42 +0200 answered a question Plotting spherical data

I 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.

If you need some kind of interpolation, I suggest you employ scipy.interpolate module. You can get many different types of N dimensional interpolation.

2011-11-04 09:54:11 +0200 commented answer sage notebook server + ssh tunneling + port forwarding

It worked! Thanks a lot!!! This way I can work on my University Cluster!

2011-11-04 09:53:32 +0200 marked best answer sage notebook server + ssh tunneling + port forwarding
  1. Connect via ssh to your server and bind port, e.g.

    ssh -L 8000:localhost:8000

    You can use some extra ssh-options if you want...

  2. Run

    ./sage -notebook

    on your server.

  3. Open a browser (locally) and type in


BTW: You do not need a X session to your server for that.

2011-11-04 09:53:32 +0200 received badge  Scholar (source)
2011-11-04 09:04:31 +0200 received badge  Student (source)
2011-11-03 18:01:41 +0200 asked a question sage notebook server + ssh tunneling + port forwarding

I have access to a remote server through a gate computer with this command:

ssh -fN -l user -L port:host:22 gate #To Bring up the tunnel

ssh -X -p port user@localhost #To open an X session to my server

Once on the server I run sage by typing "./sage" in the installation directory. Now the questions:

1)Which are the right commands to bring up the remote notebook server?

2)What should I type in my local browser? (I suppose something like 'localhost:port', but even without launching the notebook server I get the following error:'SSH-2.0-OpenSSH_4.3 Protocol mismatch')

I tried to read the instructions and the wiki, but I confess that I am at a loss.

Thanks a lot


2011-11-01 04:57:25 +0200 received badge  Supporter (source)
2011-11-01 04:57:19 +0200 commented answer 2D interpolating function from numpy arrays to spherical-plot3d

Thanks for the answer, the lambda form is especially useful. Nevertheless the fact that plot3d works and spherical_plot3d doesn't is odd

2011-10-31 12:55:12 +0200 received badge  Editor (source)
2011-10-31 07:37:11 +0200 asked a question 2D interpolating function from numpy arrays to spherical-plot3d

I need to plot an antenna emission pattern. I am importing data from a tabbed .txt file (theta[i,j],phi[i,j],r[i,j]) as numpy arrays. I then employ the same data to build a 2D interpolating function with the scipy module scipy.interpolate.interp2d. The interpolating function successfully works in plot3d, but somehow breaks spherical_plot3d. Is there anyway to build a working 2D interpolating function for spherical_plot3D?

-----Toy Data---------

v_phi=array([ 0.        ,  1.57079637,  3.14159274,  4.71238911,  6.28318548])
v_theta=array([ 0.        ,  0.78539819,  1.57079637,  2.35619456,  3.14159274])
m_r=array([[ 0.16763356,  0.25683223,  0.16649297,  0.10594339, 
   [ 0.16763356,  0.19993708,  0.31403568,  0.47359696, 
   [ 0.16763356,  0.25683223,  0.16649297,  0.10594339, 
   [ 0.16763356,  0.19993708,  0.31403568,  0.47359696, 
   [ 0.16763356,  0.25683223,  0.16649297,  0.10594339, 

------Traceback from spherical_plot3d---------

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "", line 10, in <module>
    exec compile(u'open("","w").write("# -*- coding: utf-8 -*-\\n" +     _support_.preparse_worksheet_cell(base64.b64decode("c3BoZXJpY2FsX3Bsb3QzZChmLCh4LDAsMipwaSksKHksMCxwaSksY21hcD0ncGluaycsYWRhcHRpdmU9VHJ1ZSkuc2hvdyhhc3BlY3RfcmF0aW89KDEsMSwxKSk="),globals())+"\\n"); execfile(os.path.abspath(""))
  File "", line 1, in <module>

  File "/tmp/tmpR1mM9J/", line 3, in <module>
    exec compile(u"spherical_plot3d(f,(x,_sage_const_0 ,_sage_const_2 *pi),    (y,_sage_const_0 ,pi),cmap='pink',adaptive=True).show(aspect_ratio=(_sage_const_1 ,_sage_const_1 ,_sage_const_1 ))" + '\n', '', 'single')
  File "", line 1, in <module>

  File "base.pyx", line 1052, in     (sage/plot/plot3d/base.c:9313)
  File "base.pyx", line 957, in     sage.plot.plot3d.base.Graphics3d._process_viewing_options     (sage/plot/plot3d/base.c:9112)
  File "base.pyx", line 198, in    sage.plot.plot3d.base.Graphics3d._determine_frame_aspect_ratio (sage/plot/plot3d/base.c:3404)
  File "base.pyx", line 214, in sage.plot.plot3d.base.Graphics3d._safe_bounding_box (sage/plot/plot3d/base.c:3521)
  File "parametric_surface.pyx", line 318, in sage.plot.plot3d.parametric_surface.ParametricSurface.bounding_box (sage/plot/plot3d/parametric_surface.c:2991)
  File "parametric_surface.pyx", line 366, in sage.plot.plot3d.parametric_surface.ParametricSurface.triangulate (sage/plot/plot3d/parametric_surface.c:3521)
  File "parametric_surface.pyx", line 361, in sage.plot.plot3d.parametric_surface.ParametricSurface.triangulate (sage/plot/plot3d/parametric_surface.c:3451)
  File "parametric_surface.pyx", line 576, in sage.plot.plot3d.parametric_surface.ParametricSurface.eval_grid (sage/plot/plot3d/parametric_surface.c:5152)
  File "<string>", line 4, in <lambda>
  File "expression.pyx", line 3501, in sage.symbolic.expression.Expression.substitute (sage/symbolic/expression.cpp:15529)
  File "expression.pyx", line 2089, in sage.symbolic.expression.Expression.coerce_in (sage/symbolic/expression.cpp:10788)
  File "parent_old.pyx", line 229, in sage.structure.parent_old.Parent._coerce_ (sage/structure/parent_old.c:3420)
  File "parent.pyx", line 1047, in sage.structure.parent.Parent.coerce (sage/structure/parent.c:7734)
TypeError: no canonical coercion from <type 'numpy.ndarray'> to Symbolic Ring


#importing Libraries
import numpy as np
import scipy
import scipy.interpolate

#Importing data

#getting the data
#reshaping the ...