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.Tue, 07 Nov 2017 17:29:46 +0100Sage on Mac unable to use plot3d due to Java/jmol issueshttps://ask.sagemath.org/question/39422/sage-on-mac-unable-to-use-plot3d-due-to-javajmol-issues/Hi,
I am a relative newbie to the Mac and Sage on the Mac. I tried to run the following code from the Sage tutorial on my Mac in the console mode of sage:
> sage: x, y = var('x,y')
>
> sage: plot3d(x^2 + y^2, (x,-2,2), (y,-2,2))
The error message I get is
> --------------------------------------------------------------------------- RuntimeError
> Traceback (most recent call last)
> <ipython-input-2-878191366deb> in
> <module>()
> ----> 1 plot3d(x**Integer(2) + y**Integer(2),
> (x,-Integer(2),Integer(2)),
> (y,-Integer(2),Integer(2)))
>
> /Applications/SageMath/local/lib/python2.7/site-packages/IPython/core/displayhook.pyc in __call__(self, result)
> 244 self.start_displayhook()
> 245 self.write_output_prompt()
> --> 246 format_dict, md_dict =
> self.compute_format_data(result)
> 247 self.update_user_ns(result)
> 248 self.fill_exec_result(result)
>
> /Applications/SageMath/local/lib/python2.7/site-packages/IPython/core/displayhook.pyc in compute_format_data(self, result)
> 148
> 149 """
> --> 150 return self.shell.display_formatter.format(result)
> 151
> 152 # This can be set to True by the write_output_prompt method in a
> subclass
>
> /Applications/SageMath/local/lib/python2.7/site-packages/sage/repl/display/formatter.pyc
> in format(self, obj, include, exclude)
> 158 # First, use Sage rich output if there is any
> 159 PLAIN_TEXT = u'text/plain'
> --> 160 sage_format, sage_metadata =
> self.dm.displayhook(obj)
> 161 assert PLAIN_TEXT in sage_format, 'plain text is always
> present'
> 162 if sage_format.keys() != [PLAIN_TEXT]:
>
> /Applications/SageMath/local/lib/python2.7/site-packages/sage/repl/rich_output/display_manager.pyc
> in displayhook(self, obj)
> 806 self._backend.set_underscore_variable(obj)
> 807 plain_text, rich_output =
> self._rich_output_formatter(obj,
> dict())
> --> 808 return self._backend.displayhook(plain_text,
> rich_output)
> 809
> 810 def display_immediately(self, obj,
> **rich_repr_kwds):
>
> /Applications/SageMath/local/lib/python2.7/site-packages/sage/repl/rich_output/backend_ipython.pyc
> in displayhook(self, plain_text,
> rich_output)
> 264 return ({u'text/plain': msg}, {})
> 265 elif isinstance(rich_output,
> OutputSceneJmol):
> --> 266 msg = self.launch_jmol(rich_output,
> plain_text.text.get_unicode())
> 267 return ({u'text/plain': msg}, {})
> 268 elif isinstance(rich_output,
> OutputSceneWavefront):
>
> /Applications/SageMath/local/lib/python2.7/site-packages/sage/repl/rich_output/backend_ipython.pyc
> in launch_jmol(self, output_jmol,
> plain_text)
> 367 jdata = JmolData()
> 368 if not jdata.is_jvm_available() and not
> DOCTEST_MODE:
> --> 369 raise RuntimeError('jmol cannot run, no
> suitable java version found')
> 370 launch_script = output_jmol.launch_script_filename()
> 371 from sage.env import SAGE_LOCAL
>
> RuntimeError: jmol cannot run, no
> suitable java version found
I believe I have the latest version of Java installed:
> $ java --version
> java 9.0.1
> Java(TM) SE Runtime Environment (build 9.0.1+11)
> Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)
Sage version
> $ sage --version
> SageMath version 8.0, Release Date: 2017-07-21
I would appreciate any inputs and advice about how to fix this issue. Thanks in advance!toricwebTue, 07 Nov 2017 17:29:46 +0100https://ask.sagemath.org/question/39422/Plotting in 3D in spherical coordinateshttps://ask.sagemath.org/question/8081/plotting-in-3d-in-spherical-coordinates/My problem is that I am trying to plot (in full 3D spherical coordinates) a set of values stored in a 2D lookup table or LUT. The LUT is actually stored as a numpy 1801*3601 2D array indexed by theta and phi respectively in 0.1 degree steps. The LUT in fact represents an antenna radiation pattern (i.e. antenna gain/ radiation intensity as a function of theta and phi). However, my problem generalises to any one of plotting a function in spherical coordinates.
My first attempt at plotting this in Sage was to use the 'spherical_plot3d()' function. First I defined a function called:
getGain(phiInRadians, thetaInRadians)
which returned a value from the lookup table (LUT) representing antenna gain (a positive number in decibels). Then I tried plotting this as follows:
sage: spherical_plot3d(getGain,(-3.142,3.142),(0,3.142)).show(aspect_ratio=(1,1,1))
Now this *almost* does what I want, but not quite. My LUT has a high resolution with 0.1 degree intervals. However, the 3D plot which the above command delivers (via Jmol) seems to smooth the pattern where I don't want it to be smoothed (because it has abrupt edges), and is too 'blocky' where I would like the pattern to be smooth. Is there any way I can have fine control of the step-size in phi and theta (u and v in Sage-speak), or must I leave it to Sage to control these?
I also tried a different approach, which is to use list_plot3d, but to transform the coordinates from spherical to rectangular when building up my list to plot. To discuss this case we can simplify the problem to say that we wish to plot the radiation pattern of an isotropic antenna, i.e. one which has equal gain in all directions. Thus what we are simply trying to do is to plot a sphere in 3 dimensions from a list of 3-tuples, where each tuple represents an (x,y,z) coordinate in Cartesian space. However, when generating the points to plot I transform from spherical to cartesian coordinates when setting up the list of points to plot, thus:
sage: import numpy as np
sage: r=1 # Representing the gain of an isotropic antenna
sage: listOfPointsOnSurfaceOfSphere = [ (r* sin(theta) * cos(phi), r* sin(theta)* sin(phi), r* getGain(phi,theta)* cos(theta)) for theta in np.arange(0.1,pi,0.1) for phi in np.arange(-pi,pi,0.1) ]
sage: myPlot1 = list_plot3d(listOfPointsOnSurfaceOfSphere).show()
Now what I find is that my plot is all 'spiky', whereas I was hoping to see a smooth sphere. Of course, what is happening is that I have multiple points with the same (or similar) (x,y) coordinates, but very different z coordinates, since every point on the sphere 'above the equator' (i.e. above the x,y plane) has effective neighbours as mirror images below. This seems to be screwing up the interpolation routine, which isn't able to identify that it is actually nearby points ON THE SURFACE OF THE SPHERE which should be treated as neighbours. I can (sort of) solve this problem by only plotting my antenna radiation pattern over the range of theta for 0..pi/2 rather than 0..pi. This means that my pattern now interpolates nicely, and I can choose whatever resolution I desire (within reason). However, I can now only plot the upper (or lower) half of my radiation pattern plot at a time, and not the whole 3D pattern all together.
So, in summary, I have an almost but not quite satisfactory situation whereby I can choose between:
a) A full 3D plot, but can't control the resolution, so I get unwanted blockiness/smoothing in the wrong places, or
b) A plot where I get the resolution I desire, but I can only show either above or below the x,y plane, but not all at the same time
So if anyone could help me by advising me how I could achieve the best of both worlds (i.e. full 3D plot with full control of resolution) I would be most grateful. Thanks.
deebs67Tue, 19 Apr 2011 08:28:25 +0200https://ask.sagemath.org/question/8081/publish 3d plots to web?https://ask.sagemath.org/question/7772/publish-3d-plots-to-web/I'd like to post the output of a 3d plot to the web. For example, after plotting a surface, a Jmol output is produced, which my browser renders in the notebook. I'd like this Jmol plot to be output as a file that could be uploaded to a server and embedded in a webpage (where it can still be manipulated with the mouse, etc.). Is there a way to do this?Kate StangeTue, 23 Nov 2010 13:40:54 +0100https://ask.sagemath.org/question/7772/