Created
March 18, 2017 21:24
-
-
Save ap--/c936caa9fb6e9e62b5dd335f242d9029 to your computer and use it in GitHub Desktop.
Plot a fruit fly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
import matplotlib.patches as mpatches | |
def plot_fly(ax, c, s, o): | |
# center, scale, orientation(deg) | |
c = np.array(c) | |
v = np.array([np.cos(np.radians(o)), np.sin(np.radians(o))]) | |
t = np.array([np.cos(np.radians(o+90)), np.sin(np.radians(o+90))]) | |
f1 = [ | |
mpatches.Ellipse(c-s*0.4*v, 0.8*s, 0.3*s, angle=o, facecolor='k', lw=0), | |
mpatches.Wedge(c, s, 50 + o, 150 + o, lw=2,width=0.85*s, facecolor=(1,1,1,0.3), edgecolor='k'), | |
mpatches.Wedge(c, s, 210 + o, 310 + o, lw=2,width=0.85*s, facecolor=(1,1,1,0.3), edgecolor='k'), | |
mpatches.Ellipse(c-s*0.05*v, 0.5*s, 0.4*s, angle=o, facecolor='k', lw=0), | |
mpatches.Ellipse(c+s*0.2*v, 0.25*s, 0.35*s, angle=o, facecolor='k', lw=0), | |
mpatches.Ellipse(c+s*0.24*v+s*0.10*t, 0.2*s, 0.1*s, angle=o-30, facecolor='r'), | |
mpatches.Ellipse(c+s*0.24*v-s*0.10*t, 0.2*s, 0.1*s, angle=o+30, facecolor='r'), | |
] | |
for w in f1: | |
ax.add_patch(w) | |
if __name__ == "__main__": | |
plt.figure() | |
ax = plt.subplot2grid((1,1), (0,0)) | |
ax.axis('equal') | |
plot_fly(ax, (0,0), 1, 0) | |
ax.set_xlim(-2,2) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This plots a fruit fly.