Skip to content

Instantly share code, notes, and snippets.

@nicoguaro
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicoguaro/77899900d7d8d2320006 to your computer and use it in GitHub Desktop.
Save nicoguaro/77899900d7d8d2320006 to your computer and use it in GitHub Desktop.
Plot stick men.
import matplotlib.pyplot as plt
import numpy as np
def plot_guy(x, y, frown=False, **plot_args):
"""Plot a stick man of 2 units wide and 6 units tall.
http://nbviewer.ipython.org/gist/theandygross/4544012
"""
an = np.array(np.linspace(0,2*np.pi,100))
head, = plt.plot(np.cos(an)+x, np.sin(an)+y + 5, **plot_args)
body, = plt.plot(np.array([0,0])+x, np.array([4,2])+y, **plot_args)
legs, = plt.plot(np.array([-1,0,1])+x, np.array([0,2,0])+y, **plot_args)
arms, = plt.plot(np.array([-1.5,0,1.5])+x, np.array([3.5,3,3.5])+y,
**plot_args)
eye1, = plt.plot(.2*np.cos(an)-.35 + x, .2*np.sin(an) + 5.2 + y,
**plot_args)
eye2, = plt.plot(.2*np.cos(an)+.35 + x, .2*np.sin(an) + 5.2 + y,
**plot_args)
if frown:
mouth, = plt.plot(np.cos(an[15:35]) + x, np.sin(an[15:35]) + 3.8 + y,
**plot_args)
else:
mouth, = plt.plot(np.cos(an[65:85]) + x, np.sin(an[65:85]) + 5.4 + y,
**plot_args)
plot_guy(10, 10, color='k')
plot_guy(11, 11, color='r')
plt.axis('equal')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment