Its easy to get the percentage of the moon illuminated on a given day
import ephem
a=ephem.Moon(datetime.now())
mn=a.moon_phase #illuminated percentage of the moon.
Now I would like to try and plot this to represent the moon phases. But I can't get an idea of how to fill only a percentage of a circle to simulate the earth's shadow on the moon.
My closest try is this one:
First plot the "full" moon
fig, ax = plt.subplots()
theta=np.linspace(0, 2*np.pi, 100)
r = np.sqrt(1)
c1x = r*np.cos(theta)
c1y = r*np.sin(theta)
ax.plot(c1x, c1y,color='k',lw=2,zorder=0*a)
Then add a bigger black circle to simulate the shadow passing over the moon. the offset "xmn" would move the shadow to the side so that only "n" percentage of the full moon is visible
r = np.sqrt(2)
c2x = r*np.cos(theta)
c2y = r*np.sin(theta)
xmn=1.2
ax.fill(c2x+xmn, c2y,color='k',lw=2,zorder=1*a)
Finally hide everything outside the "full moon" circle
#Circle to hide all circles
theta=np.linspace(0, 2*np.pi, 100)
# the radius of the circle
r = np.sqrt(4)
c3x = r*np.cos(theta)
c3y = r*np.sin(theta)
ax.plot(c3x, c3y,color='w')
ax.fill_between(c3x,c3y,c1y,color='w',zorder=2)
ax.fill_betweenx(c1x,c1y,c3y,color='w',zorder=2)
ax.set_xlim(-1.1, 1.1)
ax.set_ylim(-1.1, 1.1)
plt.show()
I can't find a smart way to do this. How can I find xmn?
Thanks in advance
