【10-1】
▲折れ線グラフを描画
-------------------
>>> import numpy as np
>>> import matplotlib.pyplot as plt

>>> x = np.array([1, 2, 3, 4, 5])
>>> y = np.array([10, 50, 30, 20, 40])

>>> fig = plt.figure()
>>> plt.plot(x, y)
[<matplotlib.lines.Line2D object at 0x71444570>]
>>> fig.savefig("plot1.png")
>>> plt.close()
-------------------


▲折れ線グラフの見た目を調整
-------------------
>>> import numpy as np
>>> import matplotlib.pyplot as plt

>>> x = np.array([1, 2, 3, 4, 5])
>>> y = np.array([10, 50, 30, 20, 40])

>>> fig = plt.figure()
>>> plt.grid(True)
>>> plt.plot(x, y, linewidth=4, color="red")
[<matplotlib.lines.Line2D object at 0x714477f0>]

>>> fig.savefig("plot2.png")
>>> plt.close()
-------------------


▲複数の折れ線グラフを描画
-------------------
>>> import numpy as np
>>> import matplotlib.pyplot as plt

>>> x = np.array([1, 2, 3, 4, 5])
>>> y = np.array([10, 50, 30, 20, 40])

>>> fig = plt.figure()
>>> plt.grid(True)
>>> plt.plot(x, y, linestyle="solid")
[<matplotlib.lines.Line2D object at 0x719f6a10>]
>>> plt.plot(x, y/2, linestyle="dashed")
[<matplotlib.lines.Line2D object at 0x719f6e10>]
>>> plt.plot(x, y/3, linestyle="dashdot")
[<matplotlib.lines.Line2D object at 0x719f6d10>]
>>> plt.plot(x, y, marker="o")
[<matplotlib.lines.Line2D object at 0x719f6030>]

>>> fig.savefig("plot3.png")
>>> plt.close()
-------------------


【10-2】
▲ヒストグラム表示
-------------------
>>> import numpy as np
>>> import matplotlib.pyplot as plt

>>> x = np.random.normal(50, 10, 1000)

>>> fig = plt.figure()
>>> plt.hist(x)
(array([  6.,  28., 108., 193., 259., 221., 135.,  37.,  11.,   2.]), array([18.24166386, 25.19961652, 32.15756917, 39.11552182, 46.07347448,
       53.03142713, 59.98937979, 66.94733244, 73.9052851 , 80.86323775,
       87.8211904 ]), <a list of 10 Patch objects>)
>>> fig.savefig("hist1.png")
>>> plt.close()
-------------------



▲ヒストグラムの範囲を調整
-------------------
>>> import numpy as np
>>> import matplotlib.pyplot as plt

>>> x = np.random.normal(50, 10, 1000)

>>> fig = plt.figure()
>>> plt.hist(x, range=(30, 100))
(array([ 73., 172., 257., 244., 158.,  52.,  19.,   2.,   1.,   0.]), array([ 30.,  37.,  44.,  51.,  58.,  65.,  72.,  79.,  86.,  93., 100.]), <a list of 10 Patch objects>)
>>> fig.savefig("hist2.png")
>>> plt.close()
-------------------



▲ヒストグラムの見た目を調整
-------------------
>>> import numpy as np
>>> import matplotlib.pyplot as plt

>>> x = np.random.normal(50, 10, 1000)

>>> fig = plt.figure()
>>> plt.hist(x, rwidth=0.7, color="orange")
(array([  6.,  28., 108., 193., 259., 221., 135.,  37.,  11.,   2.]), array([18.24166386, 25.19961652, 32.15756917, 39.11552182, 46.07347448,
       53.03142713, 59.98937979, 66.94733244, 73.9052851 , 80.86323775,
       87.8211904 ]), <a list of 10 Patch objects>)
>>> fig.savefig("hist3.png")
>>> plt.close()
-------------------


【10-3】
▲簡単な散布図
-------------------
>>> import matplotlib.pyplot as plt

>>> x = [1, 2, 3]
>>> y = [2, 4, 6]

>>> fig = plt.figure()
>>> ax = fig.add_subplot(1, 1, 1)
>>> ax.scatter(x, y, c='b')
<matplotlib.collections.PathCollection object at 0x72084e10>
>>> fig.savefig("scatter1.png")
>>> plt.close()
-------------------


▲散布図の見た目を調整
-------------------
>>> import numpy as np
>>> import matplotlib.pyplot as plt

>>> x1 = np.random.rand(30)
>>> y1 = np.random.rand(30)

>>> fig = plt.figure()
>>> ax = fig.add_subplot(1, 1, 1)
>>> ax.scatter(x1, y1, s=300, alpha=0.5, linewidths='2', c='#aaaaFF', edgecolors='b')
<matplotlib.collections.PathCollection object at 0x72355ab0>
>>> plt.grid(True)
>>> fig.savefig("scatter2.png")
>>> plt.close()
-------------------



▲2つのデータを1つの散布図に描画
-------------------
>>> import numpy as np
>>> import matplotlib.pyplot as plt

>>> x1 = np.random.rand(30)
>>> y1 = np.random.rand(30)
>>> x2 = np.random.rand(30)
>>> y2 = np.random.rand(30)

>>> fig = plt.figure()
>>> ax = fig.add_subplot(1, 1, 1)

>>> ax.scatter(x1, y1, s=300, alpha=0.5, linewidths='2', c='#aaaaFF', edgecolors='b')
<matplotlib.collections.PathCollection object at 0x71ef2fb0>
>>> plt.grid(True)

>>> ax.scatter(x2, y2, s=300, alpha=0.5, linewidths='2', c='#FFaaaa', edgecolors='r')
<matplotlib.collections.PathCollection object at 0x721be1b0>
>>> fig.savefig("scatter3.png")
>>> plt.close()
-------------------


【10-4】
▲簡単な棒グラフ
-------------------
>>> import matplotlib.pyplot as plt

>>> x = [1, 2, 3]
>>> y = [3, 5, 0]

>>> fig = plt.figure()
>>> plt.bar(x, y)
<BarContainer object of 3 artists>
>>> fig.savefig("bar1.png")
>>> plt.close()
-------------------


▲棒グラフの装飾その１
-------------------
>>> import matplotlib.pyplot as plt

>>> x = [1, 2, 3]
>>> y = [3, 5, 0]

>>> fig = plt.figure()
>>> plt.bar(x, y, color='r')
<BarContainer object of 3 artists>
>>> plt.grid(True)
>>> fig.savefig("bar2.png")
>>> plt.close()
-------------------



▲棒グラフの装飾その2
-------------------
>>> import matplotlib.pyplot as plt

>>> x1 = [0.9, 1.9, 2.9, 3.9, 4.9]
>>> y1 = [53, 61, 90, 84, 89]
>>> x2 = [1.1, 2.1, 3.1, 4.1, 5.1]
>>> y2 = [74, 76, 98, 32, 23]

>>> fig = plt.figure()
>>> plt.bar(x1, y1, color='r', width=0.2, align='center')
<BarContainer object of 5 artists>
>>> plt.bar(x2, y2, color='b', width=0.2, align='center')
<BarContainer object of 5 artists>

>>> plt.title("Test score")
Text(0.5, 1.0, 'Test score')
>>> plt.xlabel("Subject")
Text(0.5, 0, 'Subject')
>>> plt.ylabel("Score")
Text(0, 0.5, 'Score')
>>> fig.savefig("bar3.png")
>>> plt.close()
-------------------


【10-5】
▲基本の円グラフ
-------------------
>>> import numpy as np
>>> import matplotlib.pyplot as plt

>>> x = np.array([100, 200, 300, 400, 500])

>>> fig = plt.figure()
>>> plt.pie(x)
([<matplotlib.patches.Wedge object at 0x7205c0f0>, <matplotlib.patches.Wedge object at 0x7205c930>, <matplotlib.patches.Wedge object at 0x7205cbb0>, <matplotlib.patches.Wedge object at 0x720840f0>, <matplotlib.patches.Wedge object at 0x720846d0>], [Text(1.075962358309037, 0.22870287165240302, ''), Text(0.7360436312779136, 0.817459340184711, ''), Text(-0.33991877217145816, 1.046162142464278, ''), Text(-1.0759623315431446, -0.2287029975759841, ''), Text(0.5500001932481627, -0.9526278325909778, '')])
>>> fig.savefig("pie1.png")
>>> plt.close()
-------------------


▲ラベル付き円グラフ
-------------------
>>> import numpy as np
>>> import matplotlib.pyplot as plt

>>> x = np.array([100, 200, 300, 400, 500])
>>> label = ["A", "B", "C", "D", "E"]

>>> fig = plt.figure()
>>> plt.pie(x, labels=label, counterclock=False, startangle=90)
([<matplotlib.patches.Wedge object at 0x71d4fb50>, <matplotlib.patches.Wedge object at 0x71eb6b30>, <matplotlib.patches.Wedge object at 0x71eb6430>, <matplotlib.patches.Wedge object at 0x71eb6e70>, <matplotlib.patches.Wedge object at 0x71eb6110>], [Text(0.22870287165240302, 1.075962358309037, 'A'), Text(0.817459340184711, 0.7360436312779135, 'B'), Text(1.0461621424642782, -0.33991877217145816, 'C'), Text(-0.22870299757598442, -1.0759623315431444, 'D'), Text(-0.9526278325909774, 0.5500001932481632, 'E')])
>>> fig.savefig("pie2.png")
>>> plt.close()
-------------------


▲円グラフの見た目を調整
-------------------
>>> import numpy as np
>>> import matplotlib.pyplot as plt

>>> x = np.array([100, 200, 300, 400, 500])
>>> label = ["A", "B", "C", "D", "E"]

>>> fig = plt.figure()
>>> plt.pie(x, labels=label, counterclock=False, startangle=90, autopct="%1.1f%%", wedgeprops={'linewidth': 3, 'edgecolor':"white"})
([<matplotlib.patches.Wedge object at 0x71d5a4f0>, <matplotlib.patches.Wedge object at 0x71d5adb0>, <matplotlib.patches.Wedge object at 0x71ebfe90>, <matplotlib.patches.Wedge object at 0x71ebf390>, <matplotlib.patches.Wedge object at 0x71ebfe70>], [Text(0.22870287165240302, 1.075962358309037, 'A'), Text(0.817459340184711, 0.7360436312779135, 'B'), Text(1.0461621424642782, -0.33991877217145816, 'C'), Text(-0.22870299757598442, -1.0759623315431444, 'D'), Text(-0.9526278325909774, 0.5500001932481632, 'E')], [Text(0.12474702090131072, 0.5868885590776565, '6.7%'), Text(0.4458869128280241, 0.4014783443334073, '13.3%'), Text(0.5706338958896062, -0.18541023936624987, '20.0%'), Text(-0.12474708958690058, -0.5868885444780787, '26.7%'), Text(-0.5196151814132604, 0.30000010540808897, '33.3%')])
>>> fig.savefig("pie3.png")
>>> plt.close()
-------------------