This post is from an earlier year, meaning the information here is likely outdated. You should look for a newer post from the current year to get the newest exercises and notes.
There are only two days left before the first mandatory exercise in Fys1120 is due. Last time I posted about Mayavi I wrote in a comment that I would give you some hints on how to use it with the oblig. Actually, there are not so many useful applications for Mayavi in this particular oblig, since most plots are 2D and are better created using scitools.
In fact, the 3D plots in this oblig might also be plotted using scitools, but I decided to use Mayavi to test it out for this particular purpose.
In my code I stored the position vector for the particle in an array r, which is an array created using the NumPy function r = zeros((n,3),float). If you have stored the position in a similar array, you may use the code below to plot the position in exercise 1d, 2a and 2d. After plotting, use your mouse to find a camera angle you’re satisfied with and hit the save-button in the toolbar.
from enthought.mayavi.mlab import * fig = figure(fgcolor=(0,0,0), bgcolor=(1,1,1)) # set the background and foreground of our figure plot3d(r[:,0], r[:,1], r[:,2], tube_radius=None, color=(0.807, 0.10, 0.023)) axesm = axes() axesm.title_text_property.bold = False axesm.label_text_property.bold = False axesm.title_text_property.italic = False axesm.label_text_property.italic = False axesm.title_text_property.font_family = "times" axesm.label_text_property.font_family = "times" outlinem = outline()
A decent tip for the LaTeX-users out there is to save your file as “.pdf”. This way you may import it to a LaTeX document without losing quality. Note that the tube_radius parameter of the plot3d function must be set to None to avoid humongous PDF files.
Below you see the output I got for the different exercises, but don’t panic if your results are different. There might be some errors in my own code for all I know.