mandatory exercise – Elektromagnetisme http://elektromagnetisme.no The home of FYS1120 Mon, 20 Oct 2014 11:23:54 +0000 en-US hourly 1 https://wordpress.org/?v=4.9.3 28429679 Using Mayavi in Fys1120 oblig 1 http://elektromagnetisme.no/2010/10/05/using-mayavi-in-fys1120-oblig-1/ http://elektromagnetisme.no/2010/10/05/using-mayavi-in-fys1120-oblig-1/#respond Tue, 05 Oct 2010 14:41:17 +0000 http://mindseye.no/?p=268 Continue reading ]]>

3D plot for exercise 2d

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 n \times 3 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.

3D plot for exercise 1d 3D plot for exercise 2a 3D plot for exercise 2d ]]>
http://elektromagnetisme.no/2010/10/05/using-mayavi-in-fys1120-oblig-1/feed/ 0 268