読者です 読者をやめる 読者になる 読者になる

Matplotlibでお絵かきする練習

機械学習 Python
# coding: UTF-8
from __future__ import absolute_import, division, print_function, unicode_literals
import matplotlib.pyplot as plt
from matplotlib.patches import Circle, Wedge, Polygon, Ellipse

plt.figure(figsize=(8, 8))
ax = plt.gca()

# 身体
# http://tokeigaku.blog.jp/python/matplotlib/polygon
p = Polygon(xy=[(0.5, 0.7), (0.1, 0.2), (0.9, 0.2)], facecolor='g')
ax.add_patch(p)

# 目
p = Ellipse(xy=(0.45, 0.5), height=0.12, width=0.06, facecolor='w')
ax.add_patch(p)
p = Ellipse(xy=(0.55, 0.5), height=0.12, width=0.06, facecolor='w')
ax.add_patch(p)
p = Ellipse(xy=(0.46, 0.5), height=0.06, width=0.03, facecolor='k')
ax.add_patch(p)
p = Ellipse(xy=(0.54, 0.5), height=0.06, width=0.03, facecolor='k')
ax.add_patch(p)

# 口
# http://matplotlib.org/examples/api/patch_collection.html
p = Wedge(center=(0.5, 0.33), r=0.08, theta1=180, theta2=360, facecolor='r')
ax.add_patch(p)

# 鼻
p = plt.Line2D(xdata=(0.48, 0.3), ydata=(0.55, 0.65), color='k', linewidth=2)
ax.add_line(p)
p = plt.Line2D(xdata=(0.52, 0.7), ydata=(0.55, 0.65), color='k', linewidth=2)
ax.add_line(p)

# ?
p = plt.Line2D(xdata=(0.5, 0.48), ydata=(0.41, 0.39), color='k', linewidth=2)
ax.add_line(p)
p = plt.Line2D(xdata=(0.48, 0.5), ydata=(0.39, 0.37), color='k', linewidth=2)
ax.add_line(p)

plt.tight_layout()
plt.savefig('kyuri.png')

f:id:kujira16:20160128104329p:plain

https://gist.github.com/arosh/8dbc2313486a81fd2e3e

楽しい!!!✌('ω'✌ )三✌('ω')✌三( ✌'ω')✌

先行事例

Rで遊ぶ(その3) - ドラ○もんを描こうとした | mwSoft