@@ -161,7 +161,7 @@ <h2>Changing colors and line widths</h2>
161
161
</ div >
162
162
< 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 >
163
163
< 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
165
165
size to make it more horizontal.</ p >
166
166
< pre class ="literal-block ">
167
167
...
@@ -414,8 +414,7 @@ <h2>Figures</h2>
414
414
close. Depending on the argument it closes (1) the current figure (no
415
415
argument), (2) a specific figure (figure number or figure instance as
416
416
argument), 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 >
419
418
</ div >
420
419
< div class ="section " id ="subplots ">
421
420
< h2 > Subplots</ h2 >
@@ -504,10 +503,10 @@ <h3>Tick Locators</h3>
504
503
</ div >
505
504
< div class ="section " id ="animation ">
506
505
< 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
508
507
done mainly through clever hacks. However, things have started to change since
509
508
version 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
511
510
expect to be able to run very complex animation at 60 fps though).</ p >
512
511
< div class ="admonition-documentation admonition ">
513
512
< p class ="first admonition-title "> Documentation</ p >
@@ -610,7 +609,7 @@ <h2>Earthquakes</h2>
610
609
the last 30 days. The USGS Earthquake Hazards Program is part of the National
611
610
Earthquake Hazards Reduction Program (NEHRP) and provides several data on their
612
611
< 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,
614
613
major or minor. You would be surprised by the number of minor earthquakes
615
614
happening every hour on the planet. Since this would represent too much data
616
615
for us, we'll stick to earthquakes with magnitude > 4.5. At the time of writing,
@@ -658,7 +657,7 @@ <h2>Earthquakes</h2>
658
657
center is and to translate latitude/longitude in some coordinates matplotlib
659
658
can handle. Fortunately, there is the < a class ="reference external " href ="http://matplotlib.org/basemap/ "> basemap</ a > project (that tends to be replaced by the
660
659
more 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
662
661
earth onto a screen (there exists many different projections) and we'll stick
663
662
to the < cite > mill</ cite > projection which is rather standard for non-specialist like me.</ p >
664
663
< pre class ="code python literal-block ">
@@ -709,7 +708,7 @@ <h2>Earthquakes</h2>
709
708
< 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 >
710
709
< span class ="name "> plt</ span > < span class ="operator "> .</ span > < span class ="name "> show</ span > < span class ="punctuation "> ()</ span >
711
710
</ 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 >
713
712
< a class ="reference external image-reference " href ="scripts/earthquakes.py "> < img alt ="figures/earthquakes.png " src ="figures/earthquakes.png " style ="width: 50%; " /> </ a >
714
713
</ div >
715
714
</ div >
@@ -738,15 +737,16 @@ <h2>Regular Plots</h2>
738
737
< p > Starting from the code below, try to reproduce the graphic on the right taking
739
738
care of filled areas:</ p >
740
739
< pre class ="literal-block ">
741
- from pylab import *
740
+ import numpy as np
741
+ import maplotlib.pyplot as plt
742
742
743
743
n = 256
744
744
X = np.linspace(-np.pi,np.pi,n,endpoint=True)
745
745
Y = np.sin(2*X)
746
746
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()
750
750
</ pre >
751
751
< p > Click on figure for solution.</ p >
752
752
</ div >
@@ -760,14 +760,15 @@ <h2>Scatter Plots</h2>
760
760
< p > Starting from the code below, try to reproduce the graphic on the right taking
761
761
care of marker size, color and transparency.</ p >
762
762
< pre class ="literal-block ">
763
- from pylab import *
763
+ import numpy as np
764
+ import maplotlib.pyplot as plt
764
765
765
766
n = 1024
766
767
X = np.random.normal(0,1,n)
767
768
Y = np.random.normal(0,1,n)
768
769
769
- scatter(X,Y)
770
- show()
770
+ plt. scatter(X,Y)
771
+ plt. show()
771
772
</ pre >
772
773
< p > Click on figure for solution.</ p >
773
774
</ div >
@@ -781,21 +782,22 @@ <h2>Bar Plots</h2>
781
782
< p > Starting from the code below, try to reproduce the graphic on the right by
782
783
adding labels for red bars.</ p >
783
784
< pre class ="literal-block ">
784
- from pylab import *
785
+ import numpy as np
786
+ import maplotlib.pyplot as plt
785
787
786
788
n = 12
787
789
X = np.arange(n)
788
790
Y1 = (1-X/float(n)) * np.random.uniform(0.5,1.0,n)
789
791
Y2 = (1-X/float(n)) * np.random.uniform(0.5,1.0,n)
790
792
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')
793
795
794
796
for 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')
796
798
797
- ylim(-1.25,+1.25)
798
- show()
799
+ plt. ylim(-1.25,+1.25)
800
+ plt. show()
799
801
</ pre >
800
802
< p > Click on figure for solution.</ p >
801
803
</ div >
@@ -810,7 +812,8 @@ <h2>Contour Plots</h2>
810
812
< p > Starting from the code below, try to reproduce the graphic on the right taking
811
813
care of the colormap (see < a class ="reference internal " href ="#colormaps "> Colormaps</ a > below).</ p >
812
814
< pre class ="literal-block ">
813
- from pylab import *
815
+ import numpy as np
816
+ import maplotlib.pyplot as plt
814
817
815
818
def f(x,y): return (1-x/2+x**5+y**3)*np.exp(-x**2-y**2)
816
819
@@ -819,9 +822,9 @@ <h2>Contour Plots</h2>
819
822
y = np.linspace(-3,3,n)
820
823
X,Y = np.meshgrid(x,y)
821
824
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()
825
828
</ pre >
826
829
< p > Click on figure for solution.</ p >
827
830
</ div >
@@ -836,15 +839,17 @@ <h2>Imshow</h2>
836
839
< p > Starting from the code below, try to reproduce the graphic on the right taking
837
840
care of colormap, image interpolation and origin.</ p >
838
841
< pre class ="literal-block ">
839
- from pylab import *
842
+ import numpy as np
843
+ import maplotlib.pyplot as plt
840
844
841
845
def f(x,y): return (1-x/2+x**5+y**3)*np.exp(-x**2-y**2)
842
846
843
847
n = 10
844
848
x = np.linspace(-3,3,4*n)
845
849
y = np.linspace(-3,3,3*n)
846
850
X,Y = np.meshgrid(x,y)
847
- imshow(f(X,Y)), show()
851
+ plt.imshow(f(X,Y))
852
+ plt.show()
848
853
</ pre >
849
854
< p > Click on figure for solution.</ p >
850
855
</ div >
@@ -858,11 +863,13 @@ <h2>Pie Charts</h2>
858
863
< p > Starting from the code below, try to reproduce the graphic on the right taking
859
864
care of colors and slices size.</ p >
860
865
< pre class ="literal-block ">
861
- from pylab import *
866
+ import numpy as np
867
+ import maplotlib.pyplot as plt
862
868
863
869
n = 20
864
870
Z = np.random.uniform(0,1,n)
865
- pie(Z), show()
871
+ plt.pie(Z)
872
+ plt.show()
866
873
</ pre >
867
874
< p > Click on figure for solution.</ p >
868
875
</ div >
@@ -876,11 +883,13 @@ <h2>Quiver Plots</h2>
876
883
< p > Starting from the code above, try to reproduce the graphic on the right taking
877
884
care of colors and orientations.</ p >
878
885
< pre class ="literal-block ">
879
- from pylab import *
886
+ import numpy as np
887
+ import maplotlib.pyplot as plt
880
888
881
889
n = 8
882
890
X,Y = np.mgrid[0:n,0:n]
883
- quiver(X,Y), show()
891
+ plt.quiver(X,Y)
892
+ plt.show()
884
893
</ pre >
885
894
< p > Click on figure for solution.</ p >
886
895
</ div >
@@ -890,15 +899,16 @@ <h2>Grids</h2>
890
899
< p > Starting from the code below, try to reproduce the graphic on the right taking
891
900
care of line styles.</ p >
892
901
< pre class ="literal-block ">
893
- from pylab import *
902
+ import numpy as np
903
+ import maplotlib.pyplot as plt
894
904
895
905
axes = gca()
896
906
axes.set_xlim(0,4)
897
907
axes.set_ylim(0,3)
898
908
axes.set_xticklabels([])
899
909
axes.set_yticklabels([])
900
910
901
- show()
911
+ plt. show()
902
912
</ pre >
903
913
< p > Click on figure for solution.</ p >
904
914
</ div >
@@ -911,13 +921,14 @@ <h2>Multi Plots</h2>
911
921
</ div >
912
922
< p > Starting from the code below, try to reproduce the graphic on the right.</ p >
913
923
< pre class ="literal-block ">
914
- from pylab import *
924
+ import numpy as np
925
+ import maplotlib.pyplot as plt
915
926
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)
919
930
920
- show()
931
+ plt. show()
921
932
</ pre >
922
933
< p > Click on figure for solution.</ p >
923
934
</ div >
@@ -930,21 +941,22 @@ <h2>Polar Axis</h2>
930
941
</ div >
931
942
< p > Starting from the code below, try to reproduce the graphic on the right.</ p >
932
943
< pre class ="literal-block ">
933
- from pylab import *
944
+ import numpy as np
945
+ import maplotlib.pyplot as plt
934
946
935
- axes([0,0,1,1])
947
+ plt. axes([0,0,1,1])
936
948
937
949
N = 20
938
950
theta = np.arange(0.0, 2*np.pi, 2*np.pi/N)
939
951
radii = 10*np.random.rand(N)
940
952
width = 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)
942
954
943
955
for r,bar in zip(radii, bars):
944
956
bar.set_facecolor( cm.jet(r/10.))
945
957
bar.set_alpha(0.5)
946
958
947
- show()
959
+ plt. show()
948
960
</ pre >
949
961
< p > Click on figure for solution.</ p >
950
962
</ div >
@@ -957,10 +969,11 @@ <h2>3D Plots</h2>
957
969
</ div >
958
970
< p > Starting from the code below, try to reproduce the graphic on the right.</ p >
959
971
< pre class ="literal-block ">
960
- from pylab import *
972
+ import numpy as np
973
+ import maplotlib.pyplot as plt
961
974
from mpl_toolkits.mplot3d import Axes3D
962
975
963
- fig = figure()
976
+ fig = plt. figure()
964
977
ax = Axes3D(fig)
965
978
X = np.arange(-4, 4, 0.25)
966
979
Y = np.arange(-4, 4, 0.25)
@@ -970,7 +983,7 @@ <h2>3D Plots</h2>
970
983
971
984
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='hot')
972
985
973
- show()
986
+ plt. show()
974
987
</ pre >
975
988
< p > Click on figure for solution.</ p >
976
989
</ div >
0 commit comments