matplotlib: plot a face using circles

Viewed 39
import matplotlib.pyplot as plt


radius=float(30)
circle=plt.Circle((15,30),radius, facecolor= 'white', edgecolor='black',linestyle='solid',linewidth='2.2')
plt.gca().add_patch(circle)
plt.plot()
plt.title('Circle')
plt.show()
Circle(float(radius))

I have made a circle using the code above but I am trying to make another one for the eye inside of this one but it is not showing up if I duplicate this code and change it to be smaller. How can I fix this?

1 Answers

You can create two Circle plots circle1 and circle2 an add a patch for each one calling plt.gca().add_patch() after creating each plot and specifying a different radius for each circle with radius1 and radius2:

import matplotlib.pyplot as plt
radius1=float(30)
radius2=float(15)
circle1=plt.Circle((15,30),radius1, facecolor= 'white', edgecolor='black',linestyle='solid',linewidth='2.2')
plt.gca().add_patch(circle1)
circle2=plt.Circle((15,30),radius2, facecolor= 'white', edgecolor='black',linestyle='solid',linewidth='2.2')
plt.gca().add_patch(circle2)
plt.plot()
plt.title('Circle')
plt.show()

enter image description here

To literally draw a face, you can do something like below:

import matplotlib.pyplot as plt
radius1=30
radius2=7.5
radius3=5
radius4=5
circle1=plt.Circle((15,30),radius1, facecolor= 'white', edgecolor='black',linestyle='solid',linewidth='2.2')
plt.gca().add_patch(circle1)
circle2=plt.Circle((15,15),radius2, facecolor= 'white', edgecolor='black',linestyle='solid',linewidth='2.2')
plt.gca().add_patch(circle2)
circle3=plt.Circle((7.5,45),radius3, facecolor= 'white', edgecolor='black',linestyle='solid',linewidth='2.2')
plt.gca().add_patch(circle3)
circle4=plt.Circle((22.5,45),radius4, facecolor= 'white', edgecolor='black',linestyle='solid',linewidth='2.2')
plt.gca().add_patch(circle4)
plt.plot()
plt.title('Circle')
plt.show()

enter image description here

Related