@@ -161,7 +161,7 @@ <h2>Changing colors and line widths</h2>
161161</ div >
162162< a class ="reference external image-reference " href ="scripts/exercice_3.py "> < img alt ="figures/exercice_3.png " class ="align-right " src ="figures/exercice_3.png " /> </ a >
163163< p > First step, we want to have the cosine in blue and the sine in red and a
164- slighty thicker line for both of them. We'll also slightly alter the figure
164+ slightly thicker line for both of them. We'll also slightly alter the figure
165165size to make it more horizontal.</ p >
166166< pre class ="literal-block ">
167167...
@@ -414,8 +414,7 @@ <h2>Figures</h2>
414414close. Depending on the argument it closes (1) the current figure (no
415415argument), (2) a specific figure (figure number or figure instance as
416416argument), or (3) all figures (all as argument).</ p >
417- < p > As with other objects, you can set figure properties also setp or with the
418- set_something methods.</ p >
417+ < p > As with other objects, you can set figure properties with the set_something methods.</ p >
419418</ div >
420419< div class ="section " id ="subplots ">
421420< h2 > Subplots</ h2 >
@@ -504,10 +503,10 @@ <h3>Tick Locators</h3>
504503</ div >
505504< div class ="section " id ="animation ">
506505< h1 > < a class ="toc-backref " href ="#id7 "> Animation</ a > </ h1 >
507- < p > For quite a long time, animation in matplotlib was not an easy taks and was
506+ < p > For quite a long time, animation in matplotlib was not an easy task and was
508507done mainly through clever hacks. However, things have started to change since
509508version 1.1 and the introduction of tools for creating animation very
510- intuitively, with the possiblity to save them in all kind of formats (but don't
509+ intuitively, with the possibility to save them in all kind of formats (but don't
511510expect to be able to run very complex animation at 60 fps though).</ p >
512511< div class ="admonition-documentation admonition ">
513512< p class ="first admonition-title "> Documentation</ p >
@@ -610,7 +609,7 @@ <h2>Earthquakes</h2>
610609the last 30 days. The USGS Earthquake Hazards Program is part of the National
611610Earthquake Hazards Reduction Program (NEHRP) and provides several data on their
612611< a class ="reference external " href ="http://earthquake.usgs.gov "> website</ a > . Those data are sorted according to
613- eartquakes magnitude, ranging from significant only down to all earthquakes,
612+ earthquakes magnitude, ranging from significant only down to all earthquakes,
614613major or minor. You would be surprised by the number of minor earthquakes
615614happening every hour on the planet. Since this would represent too much data
616615for us, we'll stick to earthquakes with magnitude > 4.5. At the time of writing,
@@ -658,7 +657,7 @@ <h2>Earthquakes</h2>
658657center is and to translate latitude/longitude in some coordinates matplotlib
659658can handle. Fortunately, there is the < a class ="reference external " href ="http://matplotlib.org/basemap/ "> basemap</ a > project (that tends to be replaced by the
660659more complete < a class ="reference external " href ="http://scitools.org.uk/cartopy/ "> cartopy</ a > ) that is really
661- simmple to install and to use. First step is to define a projection to draw the
660+ simple to install and to use. First step is to define a projection to draw the
662661earth onto a screen (there exists many different projections) and we'll stick
663662to the < cite > mill</ cite > projection which is rather standard for non-specialist like me.</ p >
664663< pre class ="code python literal-block ">
@@ -709,7 +708,7 @@ <h2>Earthquakes</h2>
709708< span class ="name "> animation</ span > < span class ="operator "> =</ span > < span class ="name "> FuncAnimation</ span > < span class ="punctuation "> (</ span > < span class ="name "> fig</ span > < span class ="punctuation "> ,</ span > < span class ="name "> update</ span > < span class ="punctuation "> ,</ span > < span class ="name "> interval</ span > < span class ="operator "> =</ span > < span class ="literal number integer "> 10</ span > < span class ="punctuation "> )</ span >
710709< span class ="name "> plt</ span > < span class ="operator "> .</ span > < span class ="name "> show</ span > < span class ="punctuation "> ()</ span >
711710</ pre >
712- < p > If eveything went well, you should obtain something like this (with animation):</ p >
711+ < p > If everything went well, you should obtain something like this (with animation):</ p >
713712< a class ="reference external image-reference " href ="scripts/earthquakes.py "> < img alt ="figures/earthquakes.png " src ="figures/earthquakes.png " style ="width: 50%; " /> </ a >
714713</ div >
715714</ div >
@@ -738,15 +737,16 @@ <h2>Regular Plots</h2>
738737< p > Starting from the code below, try to reproduce the graphic on the right taking
739738care of filled areas:</ p >
740739< pre class ="literal-block ">
741- from pylab import *
740+ import numpy as np
741+ import maplotlib.pyplot as plt
742742
743743n = 256
744744X = np.linspace(-np.pi,np.pi,n,endpoint=True)
745745Y = np.sin(2*X)
746746
747- plot (X, Y+1, color='blue', alpha=1.00)
748- plot (X, Y-1, color='blue', alpha=1.00)
749- show()
747+ plt. plot (X, Y+1, color='blue', alpha=1.00)
748+ plt. plot (X, Y-1, color='blue', alpha=1.00)
749+ plt. show()
750750</ pre >
751751< p > Click on figure for solution.</ p >
752752</ div >
@@ -760,14 +760,15 @@ <h2>Scatter Plots</h2>
760760< p > Starting from the code below, try to reproduce the graphic on the right taking
761761care of marker size, color and transparency.</ p >
762762< pre class ="literal-block ">
763- from pylab import *
763+ import numpy as np
764+ import maplotlib.pyplot as plt
764765
765766n = 1024
766767X = np.random.normal(0,1,n)
767768Y = np.random.normal(0,1,n)
768769
769- scatter(X,Y)
770- show()
770+ plt. scatter(X,Y)
771+ plt. show()
771772</ pre >
772773< p > Click on figure for solution.</ p >
773774</ div >
@@ -781,21 +782,22 @@ <h2>Bar Plots</h2>
781782< p > Starting from the code below, try to reproduce the graphic on the right by
782783adding labels for red bars.</ p >
783784< pre class ="literal-block ">
784- from pylab import *
785+ import numpy as np
786+ import maplotlib.pyplot as plt
785787
786788n = 12
787789X = np.arange(n)
788790Y1 = (1-X/float(n)) * np.random.uniform(0.5,1.0,n)
789791Y2 = (1-X/float(n)) * np.random.uniform(0.5,1.0,n)
790792
791- bar(X, +Y1, facecolor='#9999ff', edgecolor='white')
792- bar(X, -Y2, facecolor='#ff9999', edgecolor='white')
793+ plt. bar(X, +Y1, facecolor='#9999ff', edgecolor='white')
794+ plt. bar(X, -Y2, facecolor='#ff9999', edgecolor='white')
793795
794796for x,y in zip(X,Y1):
795- text(x+0.4, y+0.05, '%.2f' % y, ha='center', va= 'bottom')
797+ plt. text(x+0.4, y+0.05, '%.2f' % y, ha='center', va= 'bottom')
796798
797- ylim(-1.25,+1.25)
798- show()
799+ plt. ylim(-1.25,+1.25)
800+ plt. show()
799801</ pre >
800802< p > Click on figure for solution.</ p >
801803</ div >
@@ -810,7 +812,8 @@ <h2>Contour Plots</h2>
810812< p > Starting from the code below, try to reproduce the graphic on the right taking
811813care of the colormap (see < a class ="reference internal " href ="#colormaps "> Colormaps</ a > below).</ p >
812814< pre class ="literal-block ">
813- from pylab import *
815+ import numpy as np
816+ import maplotlib.pyplot as plt
814817
815818def f(x,y): return (1-x/2+x**5+y**3)*np.exp(-x**2-y**2)
816819
@@ -819,9 +822,9 @@ <h2>Contour Plots</h2>
819822y = np.linspace(-3,3,n)
820823X,Y = np.meshgrid(x,y)
821824
822- contourf(X, Y, f(X,Y), 8, alpha=.75, cmap='jet')
823- C = contour(X, Y, f(X,Y), 8, colors='black', linewidth=.5)
824- show()
825+ plt. contourf(X, Y, f(X,Y), 8, alpha=.75, cmap='jet')
826+ C = plt. contour(X, Y, f(X,Y), 8, colors='black', linewidth=.5)
827+ plt. show()
825828</ pre >
826829< p > Click on figure for solution.</ p >
827830</ div >
@@ -836,15 +839,17 @@ <h2>Imshow</h2>
836839< p > Starting from the code below, try to reproduce the graphic on the right taking
837840care of colormap, image interpolation and origin.</ p >
838841< pre class ="literal-block ">
839- from pylab import *
842+ import numpy as np
843+ import maplotlib.pyplot as plt
840844
841845def f(x,y): return (1-x/2+x**5+y**3)*np.exp(-x**2-y**2)
842846
843847n = 10
844848x = np.linspace(-3,3,4*n)
845849y = np.linspace(-3,3,3*n)
846850X,Y = np.meshgrid(x,y)
847- imshow(f(X,Y)), show()
851+ plt.imshow(f(X,Y))
852+ plt.show()
848853</ pre >
849854< p > Click on figure for solution.</ p >
850855</ div >
@@ -858,11 +863,13 @@ <h2>Pie Charts</h2>
858863< p > Starting from the code below, try to reproduce the graphic on the right taking
859864care of colors and slices size.</ p >
860865< pre class ="literal-block ">
861- from pylab import *
866+ import numpy as np
867+ import maplotlib.pyplot as plt
862868
863869n = 20
864870Z = np.random.uniform(0,1,n)
865- pie(Z), show()
871+ plt.pie(Z)
872+ plt.show()
866873</ pre >
867874< p > Click on figure for solution.</ p >
868875</ div >
@@ -876,11 +883,13 @@ <h2>Quiver Plots</h2>
876883< p > Starting from the code above, try to reproduce the graphic on the right taking
877884care of colors and orientations.</ p >
878885< pre class ="literal-block ">
879- from pylab import *
886+ import numpy as np
887+ import maplotlib.pyplot as plt
880888
881889n = 8
882890X,Y = np.mgrid[0:n,0:n]
883- quiver(X,Y), show()
891+ plt.quiver(X,Y)
892+ plt.show()
884893</ pre >
885894< p > Click on figure for solution.</ p >
886895</ div >
@@ -890,15 +899,16 @@ <h2>Grids</h2>
890899< p > Starting from the code below, try to reproduce the graphic on the right taking
891900care of line styles.</ p >
892901< pre class ="literal-block ">
893- from pylab import *
902+ import numpy as np
903+ import maplotlib.pyplot as plt
894904
895905axes = gca()
896906axes.set_xlim(0,4)
897907axes.set_ylim(0,3)
898908axes.set_xticklabels([])
899909axes.set_yticklabels([])
900910
901- show()
911+ plt. show()
902912</ pre >
903913< p > Click on figure for solution.</ p >
904914</ div >
@@ -911,13 +921,14 @@ <h2>Multi Plots</h2>
911921</ div >
912922< p > Starting from the code below, try to reproduce the graphic on the right.</ p >
913923< pre class ="literal-block ">
914- from pylab import *
924+ import numpy as np
925+ import maplotlib.pyplot as plt
915926
916- subplot(2,2,1)
917- subplot(2,2,3)
918- subplot(2,2,4)
927+ plt. subplot(2,2,1)
928+ plt. subplot(2,2,3)
929+ plt. subplot(2,2,4)
919930
920- show()
931+ plt. show()
921932</ pre >
922933< p > Click on figure for solution.</ p >
923934</ div >
@@ -930,21 +941,22 @@ <h2>Polar Axis</h2>
930941</ div >
931942< p > Starting from the code below, try to reproduce the graphic on the right.</ p >
932943< pre class ="literal-block ">
933- from pylab import *
944+ import numpy as np
945+ import maplotlib.pyplot as plt
934946
935- axes([0,0,1,1])
947+ plt. axes([0,0,1,1])
936948
937949N = 20
938950theta = np.arange(0.0, 2*np.pi, 2*np.pi/N)
939951radii = 10*np.random.rand(N)
940952width = np.pi/4*np.random.rand(N)
941- bars = bar(theta, radii, width=width, bottom=0.0)
953+ bars = plt. bar(theta, radii, width=width, bottom=0.0)
942954
943955for r,bar in zip(radii, bars):
944956 bar.set_facecolor( cm.jet(r/10.))
945957 bar.set_alpha(0.5)
946958
947- show()
959+ plt. show()
948960</ pre >
949961< p > Click on figure for solution.</ p >
950962</ div >
@@ -957,10 +969,11 @@ <h2>3D Plots</h2>
957969</ div >
958970< p > Starting from the code below, try to reproduce the graphic on the right.</ p >
959971< pre class ="literal-block ">
960- from pylab import *
972+ import numpy as np
973+ import maplotlib.pyplot as plt
961974from mpl_toolkits.mplot3d import Axes3D
962975
963- fig = figure()
976+ fig = plt. figure()
964977ax = Axes3D(fig)
965978X = np.arange(-4, 4, 0.25)
966979Y = np.arange(-4, 4, 0.25)
@@ -970,7 +983,7 @@ <h2>3D Plots</h2>
970983
971984ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='hot')
972985
973- show()
986+ plt. show()
974987</ pre >
975988< p > Click on figure for solution.</ p >
976989</ div >
0 commit comments