Skip to content

Instantly share code, notes, and snippets.

@doctorlove doctorlove/iris1.py
Last active Sep 13, 2017

Embed
What would you like to do?
#From https://gist.github.com/aflaxman/4043086
import csv
from pylab import *
def cface(ax, x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18):
# x1 = height of upper face
# x2 = overlap of lower face
# x3 = half of vertical size of face
# x4 = width of upper face
# x5 = width of lower face
# x6 = length of nose
# x7 = vertical position of mouth
# x8 = curvature of mouth
# x9 = width of mouth
# x10 = vertical position of eyes
# x11 = separation of eyes
# x12 = slant of eyes
# x13 = eccentricity of eyes
# x14 = size of eyes
# x15 = position of pupils
# x16 = vertical position of eyebrows
# x17 = slant of eyebrows
# x18 = size of eyebrows
# transform some values so that input between 0,1 yields variety of output
x3 = 1.9*(x3-.5)
x4 = (x4+.25)
x5 = (x5+.2)
x6 = .3*(x6+.01)
x8 = 5*(x8+.001)
x11 /= 5
x12 = 2*(x12-.5)
x13 += .05
x14 += .1
x15 = .5*(x15-.5)
x16 = .25*x16
x17 = .5*(x17-.5)
x18 = .5*(x18+.1)
# top of face, in box with l=-x4, r=x4, t=x1, b=x3
e = mpl.patches.Ellipse( (0,(x1+x3)/2), 2*x4, (x1-x3), fc='white', linewidth=2)
ax.add_artist(e)
# bottom of face, in box with l=-x5, r=x5, b=-x1, t=x2+x3
e = mpl.patches.Ellipse( (0,(-x1+x2+x3)/2), 2*x5, (x1+x2+x3), fc='white', linewidth=2)
ax.add_artist(e)
# cover overlaps
e = mpl.patches.Ellipse( (0,(x1+x3)/2), 2*x4, (x1-x3), fc='white', ec='none')
ax.add_artist(e)
e = mpl.patches.Ellipse( (0,(-x1+x2+x3)/2), 2*x5, (x1+x2+x3), fc='white', ec='none')
ax.add_artist(e)
# draw nose
plot([0,0], [-x6/2, x6/2], 'k')
# draw mouth
p = mpl.patches.Arc( (0,-x7+.5/x8), 1/x8, 1/x8, theta1=270-180/pi*arctan(x8*x9), theta2=270+180/pi*arctan(x8*x9))
ax.add_artist(p)
# draw eyes
p = mpl.patches.Ellipse( (-x11-x14/2,x10), x14, x13*x14, angle=-180/pi*x12, facecolor='white')
ax.add_artist(p)
p = mpl.patches.Ellipse( (x11+x14/2,x10), x14, x13*x14, angle=180/pi*x12, facecolor='white')
ax.add_artist(p)
# draw pupils
p = mpl.patches.Ellipse( (-x11-x14/2-x15*x14/2, x10), .05, .05, facecolor='black')
ax.add_artist(p)
p = mpl.patches.Ellipse( (x11+x14/2-x15*x14/2, x10), .05, .05, facecolor='black')
ax.add_artist(p)
# draw eyebrows
plot([-x11-x14/2-x14*x18/2,-x11-x14/2+x14*x18/2],[x10+x13*x14*(x16+x17),x10+x13*x14*(x16-x17)],'k')
plot([x11+x14/2+x14*x18/2,x11+x14/2-x14*x18/2],[x10+x13*x14*(x16+x17),x10+x13*x14*(x16-x17)],'k')
if __name__ == '__main__':
with open('iris.data', 'r') as csvfile:
reader = csv.reader(csvfile)
fig = figure(figsize=(11,11))
i = 0
for row in reader:
ax = fig.add_subplot(15,10,i+1,aspect='equal')
data = row[0:3]
data.extend([0.5]*14)#whatever
data[0]= float(data[0])
data[1]= float(data[1])
data[2]= float(data[2])
data[3]= float(data[3])
cface(ax, .9, *data)
ax.axis([-1.2,1.2,-1.2,1.2])
ax.set_xticks([])
ax.set_yticks([])
i += 1
fig.subplots_adjust(hspace=0.05, wspace=0.05)
show()
#From https://gist.github.com/aflaxman/4043086
import csv
from pylab import *
def cface(ax, x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18):
# x1 = height of upper face
# x2 = overlap of lower face
# x3 = half of vertical size of face
# x4 = width of upper face
# x5 = width of lower face
# x6 = length of nose
# x7 = vertical position of mouth
# x8 = curvature of mouth
# x9 = width of mouth
# x10 = vertical position of eyes
# x11 = separation of eyes
# x12 = slant of eyes
# x13 = eccentricity of eyes
# x14 = size of eyes
# x15 = position of pupils
# x16 = vertical position of eyebrows
# x17 = slant of eyebrows
# x18 = size of eyebrows
# transform some values so that input between 0,1 yields variety of output
x3 = 1.9*(x3-.5)
x4 = (x4+.25)
x5 = (x5+.2)
x6 = .3*(x6+.01)
x8 = 5*(x8+.001)
x11 /= 5
x12 = 2*(x12-.5)
x13 += .05
x14 += .1
x15 = .5*(x15-.5)
x16 = .25*x16
x17 = .5*(x17-.5)
x18 = .5*(x18+.1)
# top of face, in box with l=-x4, r=x4, t=x1, b=x3
e = mpl.patches.Ellipse( (0,(x1+x3)/2), 2*x4, (x1-x3), fc='white', linewidth=2)
ax.add_artist(e)
# bottom of face, in box with l=-x5, r=x5, b=-x1, t=x2+x3
e = mpl.patches.Ellipse( (0,(-x1+x2+x3)/2), 2*x5, (x1+x2+x3), fc='white', linewidth=2)
ax.add_artist(e)
# cover overlaps
e = mpl.patches.Ellipse( (0,(x1+x3)/2), 2*x4, (x1-x3), fc='white', ec='none')
ax.add_artist(e)
e = mpl.patches.Ellipse( (0,(-x1+x2+x3)/2), 2*x5, (x1+x2+x3), fc='white', ec='none')
ax.add_artist(e)
# draw nose
plot([0,0], [-x6/2, x6/2], 'k')
# draw mouth
p = mpl.patches.Arc( (0,-x7+.5/x8), 1/x8, 1/x8, theta1=270-180/pi*arctan(x8*x9), theta2=270+180/pi*arctan(x8*x9))
ax.add_artist(p)
#print "(0,",-x7+.5/x8, "),", 1/x8, ", ", 1/x8, ", ", 270-180/pi*arctan(x8*x9), ", ", 270+180/pi*arctan(x8*x9)
# draw eyes
p = mpl.patches.Ellipse( (-x11-x14/2,x10), x14, x13*x14, angle=-180/pi*x12, facecolor='white')
ax.add_artist(p)
p = mpl.patches.Ellipse( (x11+x14/2,x10), x14, x13*x14, angle=180/pi*x12, facecolor='white')
ax.add_artist(p)
# draw pupils
p = mpl.patches.Ellipse( (-x11-x14/2-x15*x14/2, x10), .05, .05, facecolor='black')
ax.add_artist(p)
p = mpl.patches.Ellipse( (x11+x14/2-x15*x14/2, x10), .05, .05, facecolor='black')
ax.add_artist(p)
# draw eyebrows
plot([-x11-x14/2-x14*x18/2,-x11-x14/2+x14*x18/2],[x10+x13*x14*(x16+x17),x10+x13*x14*(x16-x17)],'k')
plot([x11+x14/2+x14*x18/2,x11+x14/2-x14*x18/2],[x10+x13*x14*(x16+x17),x10+x13*x14*(x16-x17)],'k')
def with_data():
with open('iris.data', 'r') as csvfile:
reader = csv.reader(csvfile)
fig = figure(figsize=(11,11))
i = 0
for row in reader:
ax = fig.add_subplot(15,10,i+1,aspect='equal')
data = [0.5]*17#whatever
data[0] = float(row[1])
data[1] = float(row[0])
data[2] = float(row[2])
data[12] = float(row[3])
cface(ax, .9, *data)
ax.axis([-1.2,1.2,-1.2,1.2])
ax.set_xticks([])
ax.set_yticks([])
i += 1
fig.subplots_adjust(hspace=0.05,wspace=0.0)
show()
def without_data():
fig = figure(figsize=(11,11))
i = 0
ax = fig.add_subplot(15,10,i+1,aspect='equal')
data = [0.5]*17#whatever
data[1] = 2.0
data[4] = 3.0
data[7] = 4.0
data[14] = 5.0
cface(ax, .9, *data)
ax.axis([-1.2,1.2,-1.2,1.2])
ax.set_xticks([])
ax.set_yticks([])
fig.subplots_adjust(hspace=0.05, wspace=0.05)
show()
if __name__ == '__main__':
with_data()
@doctorlove

This comment has been minimized.

Copy link
Owner Author

doctorlove commented Sep 13, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.