Python Matplotlib §„種ƒ—ƒ­ƒƒƒˆ...

download Python Matplotlib §„種ƒ—ƒ­ƒƒƒˆ mizutani/python/print/matplotlib/...Python Matplotlib

of 13

  • date post

    25-Jul-2019
  • Category

    Documents

  • view

    222
  • download

    0

Embed Size (px)

Transcript of Python Matplotlib §„種ƒ—ƒ­ƒƒƒˆ...

  • Python Matplotlib

    2016 ver.0.06

    matplotlib python2 3

    (ffmpeg)Excel

    matplotlib matplotlib doc PDF 2,800

    python matplotlib

    matplotlib matplotlib GalleryMatplotlib 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

    http://matplotlib.org/contents.htmlhttp://matplotlib.org/Matplotlib.pdfhttp://matplotlib.org/gallery.htmlhttp://matplotlib.org/examples/index.html
  • 1 matplotlib

    matplotlib Pythonmatplotlib

    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] x1, y1 x2, y2 x3, y3 3 xy-

    plt 3 (x1, y1), (x2, y2) (x3, y3)

    simple plot00.py

    [ 1] 1 MacOX/Linux shell Shebang Windows (win-

    dows10)

    [ 2] 2UTF-8

    UTF-8

    7

    simple plot00.py1 #!/usr/bin/env python

    2 # -*- coding: utf-8 -*-

    3 # .matplotlib/matplotlibrc 4 # font.family : IPAexGothic

    5 # IPAex http://ipafont.ipa.go.jp6

    7 simple_plot00.py

    8 1 39

    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,14plt.plot(xk, yk, ro)x, y- xk yk (xk, yk) 1

    ro red circle()15

    x-16 y-

    2

    http://matplotlib.org/users/installing.html
  • 17,18,19x- 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.py15 plt.axis

    2.2

    simple plot00.py 1 plot

    n (x1, y1), (x2, y2), (x3, y3), . . . , (xn, yn)x y

    2 xlist, ylist

    xlist = [x1, x2, x3, . . . , xn]

    ylist = [y1, y2, y3, . . . , yn]

    simple plot0.py simple plot00.py 2

    simple plot0.py1 #!/usr/bin/env python

    2 # -*- coding: utf-8 -*-

    3

    4 simple_plot0.py

    5 3 xy-6

    7 import matplotlib.pyplot as plt

    8

    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

    matplotlibx- y-

    f(x) I = [xa, xb]

    I

    xa = x0 < x1 < x2 < x3 < < xn1 < xn = xb

    xk f(xk) (xk, f(xk)), k = 0, . . . , n2

    f(x) = x2 [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

    func plot0.py1 #!/usr/bin/env python

    2 # -*- coding: utf-8 -*-

    3

    4 func_plot0.py

    5 numpy 6

    7 import matplotlib.pyplot as plt

    8

    9 def frange(startpt, endpt, step):

    10 nlist = [startpt]

    11 next = startpt + step

    4

  • 12 while next

  • x0 (0, 102 {(xk, xk+1)}k=0,...,

    expansion.py1 #!/usr/bin/env python

    2 # -*- coding: utf-8 -*-

    3

    4 expansion.py

    5 plotting orbit (x_i, x_{i+1}) of 1-dim expansion(binary and continued expansion)

    6

    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 Dn (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

    http://docs.scipy.org/doc/
  • 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

    numpynumpy

    xlist=[x0, x1, . . . , xn] flist=[f(x0), f(x1), . . . , f(xn)] for

    7

  • f(xlist) f(x) x2

    >>> x = numpy.linspace(-2, 2, 10)

    >>> x

    array([-2. , -1.55555556, -1.11111111, -0.66666667, -0.22222222,

    0.22222222, 0.66666667, 1.11111111, 1.55555556, 2. ])

    >>> x ** 2

    array([ 4. , 2.41975309, 1.2345679 , 0.44444444, 0.04938272,

    0.04938272, 0.44444444, 1.2345679 , 2.41975309, 4. ])

    3.3 Python shell x3

    numpy func plot10.py numpy.linspace 8

    func plot1.py

    func plot1.py1 #!/usr/bin/env python

    2 # -*- coding: utf-8 -*-

    3

    4 func_plot1.py

    5 numpy6

    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(rGraphs of $f(x)=x^2$, fontsize=20)

    21 #plt.savefig(image/func_plot1.png)

    22 plt.show()

    3.2

    plotro

    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.plotb-

    11 12

    9

  • 2 ( 8)

    3.4

    plotrob-

    colormakrkerls linestyle

    func plot2.py [, ] cos, sin, tan 313 marker=s ls=None tan(x)

    11,12,13 plot label

    18plt.legend()

    func plot2.py1 #!/usr/bin/env python

    2 # -*- coding: utf-8 -*-

    3

    4 simple_plot2.py

    5 6

    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.py1 #!/usr/bin/env python

    2 # -*- coding: utf-8 -*-

    3

    4 simple_plot3.py

    5 6

    7 import numpy as np

    8 import matplotlib.pyplot as plt