Python Matplotlib 2016 ver.0.06 matplotlib python 2 3 (ffmpeg ) Excel matplotlib matplotlib doc PDF 2,800 python matplotlib matplotlib matplotlib Gallery Matplotlib Examples 1 matplotlib 2 2 pyplot 2 2.1 1........................ 2 2.2........................... 3 2.3 numpy.................. 4 2.4................................... 5 3 numpy 6 3.1 numpy.................................... 6 3.2......................................... 8 3.3.......................................... 9 3.4.................................. 10 3.5.............................................. 11 A matplotlib 13 1
1 matplotlib matplotlib Python matplotlib numpy matplotlib Installing A 2 pyplot matplotlib 1 matplotlib.pyplot matplotlib.pyplot plt import import numpy as np import matplotlib.pyplot as plt numpy ns 2.1 1 [Kg] [cm] x 1, y 1 x 2, y 2 x 3, y 3 3 xy- plt 3 (x 1, y 1 ), (x 2, y 2 ) (x 3, y 3 ) simple plot00.py [ 1] 1 MacOX/Linux shell Shebang Windows (windows10) [ 2] 2 UTF-8 UTF-8 7 simple plot00.py 3 #.matplotlib/matplotlibrc 4 # font.family : IPAexGothic 5 # IPAex http://ipafont.ipa.go.jp 7 simple_plot00.py 8 1 3 9 10 import matplotlib.pyplot as plt 11 12 plt.plot(62, 173, ro ) 13 plt.plot(53, 163, ro ) 14 plt.plot(72, 170, ro ) 15 plt.xlim(50, 80) 16 plt.ylim(150, 180) 17 plt.xlabel(u [Kg] ) 18 plt.ylabel(u [cm] ) 19 plt.title(u ) 20 #plt.savefig( image/simple_plot00.png ) 21 plt.show() 12,13,14 plt.plot(x k, y k, ro ) x, y- x k y k (x k, y k ) 1 ro red circle( ) 15 x- 16 y- 2
17,18,19 x- y- plt.xlabel( ) plt.ylabel( ) plt.title( ) 21 plt.show() 20 PNG.png(PNG),.pdf(PDF),.eps(EPS),.svg(SVG) JPEG 2.1 simple plot00.py 1 1 simple plot00.py IPAex.matplotlib/matplotlibrc 2.2 simple plot00.py 15 plt.axis 2.2 simple plot00.py 1 plot n (x 1, y 1 ), (x 2, y 2 ), (x 3, y 3 ),..., (x n, y n ) x y 2 xlist, ylist xlist = [x 1, x 2, x 3,..., x n ] ylist = [y 1, y 2, y 3,..., y n ] simple plot0.py simple plot00.py 2 4 simple_plot0.py 5 3 xy- 7 import matplotlib.pyplot as plt 8 simple plot0.py 3
9 xlist = [62, 53, 72] 10 ylist = [173, 163, 170] 11 plt.plot(xlist, ylist, ro ) 12 plt.xlim(50, 80) 13 plt.ylim(150, 180) 14 plt.xlabel(u [Kg] ) 15 plt.ylabel(u [cm] ) 16 plt.title(u ) 17 #plt.savefig( image/simple_plot0.png ) 18 plt.show() 2.3 simple plot0.py simple plot00.py 2.3 numpy matplotlib x- y- f(x) I = [x a, x b ] I x a = x 0 < x 1 < x 2 < x 3 < < x n 1 < x n = x b x k f(x k ) (x k, f(x k )), k = 0,..., n 2 f(x) = x 2 [ 2, 2] 0.25 2.3 matplotlib func plot0.py Python range xrange 9 15 frange(startpt, endpt, step) 17 startpt endpt step xlist 18 21 2 flist 4 func_plot0.py 5 numpy 7 import matplotlib.pyplot as plt 8 9 def frange(startpt, endpt, step): 10 nlist = [startpt] 11 next = startpt + step func plot0.py 4
12 while next <= endpt: 13 nlist.append(next) 14 next += step 15 return(nlist) 16 17 xlist = frange(-2, 2, 0.25) 18 flist = [] 19 for x in xlist: 20 fx = x ** 2 21 flist.append(fx) 22 23 plt.plot(xlist, flist, ro ) 24 plt.xlim(-2,2) 25 plt.ylim(-0.5, 5) 26 plt.axhline(0, c= b, ls= -, lw=0.5)# x ( x=0) 27 plt.axvline(0, c= b, ls= -, lw=0.5)# y ( y=0) 28 plt.xlabel( x, fontsize=18) 29 plt.ylabel( f(x), fontsize=18) 30 31 plt.title( Graphs of f(x)=x ** 2 ) 32 #plt.savefig( image/func_plot0.png ) 33 plt.show() 2.4 func plot0.py [ 4, 4] 3 1 2 x3 + x 2 3x math [ π, π] sin (0, 20] log x, y- plt.xlim,plt.ylim 2.4 I = [0, 1) f : I I I x 0 I f O(f, x 0 ) x 0 O(f, x 0 ) = {x 0, x 1, x 2,..., x n,... }, x k+1 = f(x k ). 2 {(x k, x k+1 )} k=0,..., f {(x, y) y = f(x)} [0, 1) b(x) = 2x (mod 1) = 2x a(x), a(x) = 2x {0, 1} x [0, 1)] 2 x = k=1 a k (x) 2 k, a k (x) = a(b k (x)) (0, 1] g(x) = 1 1 x c(x), c(x) = N x x [0, 1)] 1 x = 1 c 1 (x) + 1 c 2 (x) +... 1 + c k (x) + 1..., c k (x) = c(g k (x)). 5
x 0 (0, 10 2 {(x k, x k+1 )} k=0,..., expansion.py 4 expansion.py 5 plotting orbit (x_i, x_{i+1}) of 1-dim expansion(binary and continued expansion) 7 import math 8 import matplotlib.pyplot as plt 9 10 def binary_expand(x): 11 return(2 * x - math.floor(2 * x)) 12 13 def cfraction_expand(x): 14 return(1/x - math.floor(1/x)) 15 16 N = 20000 17 x0 = math.sqrt(2)-1 18 19 xlist = [] 20 ylist = [] 21 22 for k in range(0,n): 23 x1 = binary_expand(x0) 24 # x1 = cfraction_expand(x0) 25 xlist.append(x0) 26 ylist.append(x1) 27 x0 = x1 28 29 plt.plot(xlist, ylist, r. ) 30 plt.show() f : D D n (dynamical system) 2.5 (0, 0) 1 2 expansion.py 3 numpy 2.3 f(x) f *1 3.1 numpy numpy python Python A Numpy User Guide numpy matplotlib numpy np import numpy as np *1 Python matplotlib 6
I = [a, b] 2 1. numpy.arange I = [a, b] dx xlist xlist = np.arange(a, b, dx) Python shell [ 2, 2] 0.5 x >>> import numpy >>> x = numpy.arange(-2, 2, 0.5) >>> x array([-2., -1.5, -1., -0.5, 0., 0.5, 1., 1.5]) numpy.arange array 2. numpy.linspace I = [a, b] n xlist xlist = np.linspace(a, b, n) n xlist = np.linspace(a, b) Python shell [ 2, 2] 20 x >>> x = numpy.linspace(-2, 2, 20) >>> x array([-2., -1.78947368, -1.57894737, -1.36842105, -1.15789474, -0.94736842, -0.73684211, -0.52631579, -0.31578947, -0.10526316, 0.10526316, 0.31578947, 0.52631579, 0.73684211, 0.94736842, 1.15789474, 1.36842105, 1.57894737, 1.78947368, 2. ]) [ 2, 2] x >>> x = numpy.linspace(-2, 2) >>> x array([-2., -1.91836735, -1.83673469, -1.75510204, -1.67346939, -1.59183673, -1.51020408, -1.42857143, -1.34693878, -1.26530612, -1.18367347, -1.10204082, -1.02040816, -0.93877551, -0.85714286,...... 0.85714286, 0.93877551, 1.02040816, 1.10204082, 1.18367347, 1.26530612, 1.34693878, 1.42857143, 1.51020408, 1.59183673, 1.67346939, 1.75510204, 1.83673469, 1.91836735, 2. ]) 3.1 Python shell I = [ π, π] 0.2 numpy.arange 3.2 Python shell I = [ π, π] numpy.linspace 50 π numpy.pi numpy numpy xlist=[x 0, x 1,..., x n ] flist=[f(x 0 ), f(x 1 ),..., f(x n )] for 7
f(xlist) f(x) x 2 3.3 >>> x = numpy.linspace(-2, 2, 10) >>> x array([-2., -1.55555556, -1.11111111, -0.66666667, -0.22222222, >>> x ** 2 0.22222222, 0.66666667, 1.11111111, 1.55555556, 2. ]) array([ 4., 2.41975309, 1.2345679, 0.44444444, 0.04938272, 0.04938272, 0.44444444, 1.2345679, 2.41975309, 4. ]) Python shell x 3 numpy func plot10.py numpy.linspace 8 func plot1.py func plot1.py 4 func_plot1.py 5 numpy 7 import numpy as np 8 import matplotlib.pyplot as plt 9 10 x = np.linspace(-2, 2, 8) 11 plt.plot(x, x ** 2, ro ) 12 #plt.plot(x, x ** 2, b- ) 13 plt.xlim(-2,2) 14 plt.ylim(-0.5, 5) 15 plt.axhline(0, color= b, ls= -, lw=0.5)# x ( x=0) 16 plt.axvline(0, color= b, ls= -, lw=0.5)# y ( y=0) 17 plt.xlabel(r $x$, fontsize=18) 18 plt.ylabel(r $f(x)$, fontsize=18) 19 20 plt.title(r Graphs of $f(x)=x^2$, fontsize=20) 21 #plt.savefig( image/func_plot1.png ) 22 plt.show() 3.2 plot ro 1 8
red r blue b green g cyan c magenta m yellow y black k white w 1 matplotlib (color)., o v ^ < > s 5 p 6 h 6 2 H 8 8 * D d 2 matplotlib (marker) 3.4 markersize plt.plot(xlist, ylist, b+, markersize=10) 3.5 3.3 3.6 func plot1.py 12 # 2 12 plt.plot b- 11 12 9
2 ( 8) 3.4 plot ro b- color makrker ls linestyle func plot2.py [ π, π] cos, sin, tan 3 13 marker= s ls= None tan(x) 11,12,13 plot label 18 plt.legend() func plot2.py 4 simple_plot2.py 5 7 import numpy as np 8 import matplotlib.pyplot as plt 9 10 x = np.linspace(-np.pi, np.pi) 11 plt.plot(x, np.cos(x), color= r, ls= -, label= cos ) 12 plt.plot(x, np.sin(x), color= b, ls= -, label= sin ) 13 plt.plot(x, np.tan(x), color= c, marker= s, ls= None, label= tan ) 14 plt.xlim(-np.pi, np.pi) 15 plt.ylim(-1.5,1.5) 16 plt.axhline(0, ls= -, c= b, lw=0.5)# x ( x=0) 17 plt.axvline(0, ls= -, c= b, lw=0.5)# y ( y=0) 18 plt.legend()# 19 plt.xlabel( x ) 20 plt.ylabel( y ) 21 22 plt.title( Graphs of Trigonometric functions ) 23 #plt.savefig( image/func_plot2.png ) 24 plt.show() 3.7 func plot2.py 10
3 [ π, π] sin(x), cos(x) tan(x) 3.5 plot ls 3 solid - dashed -- dashdot -. dotted : None 3 matplotlib (line style) plot linewidth lw func plot3.py [ π, π] sin(x), sin(x + 1), sin(x + 2),sin(x + 3), sin(x + 4) 4 func plot3.py 4 simple_plot3.py 5 7 import numpy as np 8 import matplotlib.pyplot as plt 9 10 x = np.linspace(-np.pi, np.pi) 11 plt.plot(x, np.cos(x), color= r, ls= -, lw=1.0, label= lw=1 ) 12 plt.plot(x, np.cos(x+1), color= b, ls= -, lw=2.0, label= lw=2 ) 13 plt.plot(x, np.cos(x+2), color= g, ls= -, lw=3.0, label= lw=3 ) 14 plt.plot(x, np.cos(x+3), color= c, ls= -, lw=4.0, label= lw=4 ) 15 plt.plot(x, np.cos(x+4), color= m, ls= -, lw=5.0, label= lw=5 ) 16 plt.xlim(-np.pi, np.pi) 17 plt.ylim(-1.5,1.5) 18 plt.axhline(0, ls= -, c= b, lw=0.5)# x ( x=0) 19 plt.axvline(0, ls= -, c= b, lw=0.5)# y ( y=0) 20 plt.legend()# 11
21 plt.xlabel( x ) 22 plt.ylabel( y ) 23 24 plt.title( Variation of Line widths ) 25 #plt.savefig( image/func_plot3.png ) 26 plt.show() 3.8 func plot3.py 4 [ π, π] sin (Lissajous) xy- (x, y) t x(t) = sin ωt, y(t) = cos t ω > 0 ω lissajous.py lissajous.py 4 lissajous.py 5 sin(omega * t), cos(t)) 7 import numpy as np 8 import matplotlib.pyplot as plt 9 10 omega = np.sqrt(3) 11 t = np.arange(0, 100, 0.1) 12 plt.plot(np.sin(omega * t), np.sin(t), b ) 13 14 plt.xlabel( x ) 15 plt.ylabel( y ) 16 plt.title(r Lissajous curve: $\omega$= + str(omega)) 17 #plt.savefig( image/lissajous.png ) 18 plt.show() 12
5 ω = 3 t 0 100 t 3.9 lissajous.py 10 omega 0.8 1.5 np.sqrt(3) A matplotlib 13