.. code:: python # this ipython magic command imports pylab and allows the plots to reside within the notebook %pylab inline .. parsed-literal:: Populating the interactive namespace from numpy and matplotlib The following examples are based on Florian Lhuillier's lecture on Matlab which can be found online: http://geophysik.uni-muenchen.de/~lhuillier/teaching/AD2010/ Pylab continued ... =================== Examples based on "... des données sous MATLAB" ----------------------------------------------- .. code:: python set_printoptions(precision=2, suppress=True) Excercise 1 ~~~~~~~~~~~ .. code:: python aa = loadtxt('dipole_ref.txt') .. code:: python aa.shape .. parsed-literal:: (21481, 3) .. code:: python subplot(211) plot(aa[:,0], aa[:,1]) xlabel("test1") subplot(212) plot(aa[:,0], aa[:,2]) xlabel('TEST2') subplots_adjust(hspace=.5) .. image:: 4_pylab_files/4_pylab_6_0.png Excercise 2 ~~~~~~~~~~~ .. code:: python aa = loadtxt('dipole_ref.txt') .. code:: python bb = loadtxt('dipole_pert.txt') .. code:: python t = bb[:,0]; .. code:: python d = bb[:,2] - interp(t, aa[:,0],aa[:,2]); .. code:: python semilogy(t, abs(d)) .. parsed-literal:: [] .. image:: 4_pylab_files/4_pylab_12_1.png Excercise 3 ~~~~~~~~~~~ .. code:: python d = genfromtxt('spectre.txt', skip_header=1, dtype=None, names=('name', 'number', 'amplitude')) .. code:: python d .. parsed-literal:: array([(b'a', 1, 9.5960921), (b'b', 2, 9.4450301), (b'c', 3, 7.5000147), (b'd', 4, 6.7446755), (b'e', 5, 4.7442346), (b'f', 6, 4.3416987), (b'g', 7, 2.9904522), (b'h', 8, 2.3769902), (b'i', 9, 1.8908512), (b'j', 10, 1.3387981), (b'k', 11, 1.0044059), (b'l', 12, 0.79748122), (b'm', 13, 0.5872564), (b'n', 14, 0.48502449), (b'p', 15, 0.34799267), (b'q', 16, 0.28167023), (b'r', 17, 0.20974501), (b's', 18, 0.16570928), (b't', 19, 0.12762576), (b'u', 20, 0.098378887)], dtype=[('name', 'S1'), ('number', '] .. image:: 4_pylab_files/4_pylab_20_1.png Excercise 4 ~~~~~~~~~~~ .. code:: python aa = loadtxt('anomalie.txt') .. code:: python nx = len( unique(aa[:,0])); nx .. parsed-literal:: 21 .. code:: python ny = len( unique(aa[:,1])); ny .. parsed-literal:: 11 .. code:: python X=aa[:,0].reshape((nx, ny)); .. code:: python Y=aa[:,1].reshape((nx, ny)); .. code:: python data = aa[:,2].reshape((nx, ny)); .. code:: python pcolor( X, Y, data) .. parsed-literal:: .. image:: 4_pylab_files/4_pylab_28_1.png .. code:: python imshow(data.T, extent=[X.min(), X.max(), Y.min(), Y.max()], interpolation='gaussian', origin='lower') colorbar() .. parsed-literal:: .. image:: 4_pylab_files/4_pylab_29_1.png .. code:: python contourf( X, Y, data) colorbar() .. parsed-literal:: .. image:: 4_pylab_files/4_pylab_30_1.png .. code:: python from scipy.ndimage import zoom .. code:: python data = array(zoom(data,3)).T .. code:: python contourf(data, extent=[X.min(), X.max(), Y.min(), Y.max()]) colorbar() #axis("equal") .. parsed-literal:: .. image:: 4_pylab_files/4_pylab_33_1.png .. code:: python imshow(data, extent=[X.min(), X.max(), Y.min(), Y.max()], interpolation='gaussian', origin='lower', aspect=1) colorbar() .. parsed-literal:: .. image:: 4_pylab_files/4_pylab_34_1.png