0

I have two plots with many circles on them and I am trying to calculate the area of the shaded region. I asked the question in Math Stack and was bombarded with criticisms as the question is irrelevant to the page. If you may help me, I would really appreciate it.

import matplotlib.pyplot as plt
from pylab import *
import numpy as np
import math
np.random.seed(10)

def filledcircle(x, y, r):
    circle = plt.Circle((x, y), r,color='lightgray',fill=True, ec='none')
    return plt.gca().add_artist(circle)

After defining the function,

fig, ax = plt.subplots(figsize=(8, 8))
ax.set_xlim((0, 1))
ax.set_ylim((0, 1))
x = 0.5; y = 0.5; r = 0.2
degree = np.pi
filledcircle(x-r, y, r/2)
filledcircle(x-r/2, y, r/2)
filledcircle(x, y-r, r/2)
filledcircle(x, y-r/2, r/2)
filledcircle(x+r, y, r/2)
filledcircle(x+r/2, y, r/2)
filledcircle(x, y+r, r/2)
filledcircle(x, y+r/2, r/2)
filledcircle(x -r*np.sin(0.75*degree), y + r*np.cos(0.75*degree), r/2)
filledcircle(x -r*np.sin(1.25*degree), y + r*np.cos(1.25*degree), r/2)
filledcircle(x -r*np.sin(1.75*degree), y + r*np.cos(1.75*degree), r/2)
filledcircle(x -r*np.sin(0.25*degree), y + r*np.cos(0.25*degree), r/2)
filledcircle(x -1.5*r*np.sin(0.75*degree), y + 1.5*r*np.cos(0.75*degree), r/2)
filledcircle(x -1.5*r*np.sin(0.25*degree), y + 1.5*r*np.cos(0.25*degree), r/2)
filledcircle(x -1.5*r*np.sin(1.75*degree), y + 1.5*r*np.cos(1.75*degree), r/2)
filledcircle(x -1.5*r*np.sin(1.25*degree), y + 1.5*r*np.cos(1.25*degree), r/2)
filledcircle(x -1.5*r*np.sin(0*degree), y + 1.5*r*np.cos(0*degree), r/2)
filledcircle(x -1.5*r*np.sin(0.5*degree), y + 1.5*r*np.cos(0.5*degree), r/2)
filledcircle(x -1.5*r*np.sin(1*degree), y + 1.5*r*np.cos(1*degree), r/2)
filledcircle(x -1.5*r*np.sin(1.5*degree), y + 1.5*r*np.cos(1.5*degree), r/2)
filledcircle(x -1.5*r*np.sin(0.125*degree), y + 1.5*r*np.cos(0.125*degree), r/2)
filledcircle(x -1.5*r*np.sin(0.375*degree), y + 1.5*r*np.cos(0.375*degree), r/2)
filledcircle(x -1.5*r*np.sin(0.625*degree), y + 1.5*r*np.cos(0.625*degree), r/2)
filledcircle(x -1.5*r*np.sin(0.875*degree), y + 1.5*r*np.cos(0.875*degree), r/2)
filledcircle(x -1.5*r*np.sin(1.125*degree), y + 1.5*r*np.cos(1.125*degree), r/2)
filledcircle(x -1.5*r*np.sin(1.375*degree), y + 1.5*r*np.cos(1.375*degree), r/2)
filledcircle(x -1.5*r*np.sin(1.625*degree), y + 1.5*r*np.cos(1.625*degree), r/2)
filledcircle(x -1.5*r*np.sin(1.875*degree), y + 1.5*r*np.cos(1.875*degree), r/2)

plt.show()

Output: enter image description here

fig, ax = plt.subplots(figsize=(8, 8))
ax.set_xlim((0, 1))
ax.set_ylim((0, 1))

x = 0.5; y = 0.5; r = 0.2
degree = np.pi

filledcircle(x, y, r/2)
filledcircle(x-r, y, r/2)
filledcircle(x, y-r, r/2)
filledcircle(x+r, y, r/2)
filledcircle(x, y+r, r/2)
filledcircle(x -r*np.sin(0.75*degree), y + r*np.cos(0.75*degree), r/2)
filledcircle(x -r*np.sin(1.25*degree), y + r*np.cos(1.25*degree), r/2)
filledcircle(x -r*np.sin(1.75*degree), y + r*np.cos(1.75*degree), r/2)
filledcircle(x -r*np.sin(0.25*degree), y + r*np.cos(0.25*degree), r/2)
filledcircle(x -2*r*np.sin(0.75*degree), y + 2*r*np.cos(0.75*degree), r/2)
filledcircle(x -2*r*np.sin(0.25*degree), y + 2*r*np.cos(0.25*degree), r/2)
filledcircle(x -2*r*np.sin(1.75*degree), y + 2*r*np.cos(1.75*degree), r/2)
filledcircle(x -2*r*np.sin(1.25*degree), y + 2*r*np.cos(1.25*degree), r/2)
filledcircle(x -2*r*np.sin(0*degree), y + 2*r*np.cos(0*degree), r/2)
filledcircle(x -2*r*np.sin(0.5*degree), y + 2*r*np.cos(0.5*degree), r/2)
filledcircle(x -2*r*np.sin(1*degree), y + 2*r*np.cos(1*degree), r/2)
filledcircle(x -2*r*np.sin(1.5*degree), y + 2*r*np.cos(1.5*degree), r/2)
filledcircle(x -2*r*np.sin(0.125*degree), y + 2*r*np.cos(0.125*degree), r/2)
filledcircle(x -2*r*np.sin(0.375*degree), y + 2*r*np.cos(0.375*degree), r/2)
filledcircle(x -2*r*np.sin(0.625*degree), y + 2*r*np.cos(0.625*degree), r/2)
filledcircle(x -2*r*np.sin(0.875*degree), y + 2*r*np.cos(0.875*degree), r/2)
filledcircle(x -2*r*np.sin(1.125*degree), y + 2*r*np.cos(1.125*degree), r/2)
filledcircle(x -2*r*np.sin(1.375*degree), y + 2*r*np.cos(1.375*degree), r/2)
filledcircle(x -2*r*np.sin(1.625*degree), y + 2*r*np.cos(1.625*degree), r/2)
filledcircle(x -2*r*np.sin(1.875*degree), y + 2*r*np.cos(1.875*degree), r/2)

plt.show()

Output: enter image description here

tcokyasar
  • 582
  • 1
  • 9
  • 26
  • 2
    It is still unclear what your are asking. What is your question? – Vojtěch Aug 09 '18 at 21:25
  • I want to calculate the shaded region's area. What is not clear? I may use some pixel counting method, but, don't know how to implement. – tcokyasar Aug 09 '18 at 22:51
  • I just figured out, it was [this](https://stackoverflow.com/questions/28576203/how-to-count-the-number-of-pixels-of-a-certain-color-in-python) easy. – tcokyasar Aug 10 '18 at 01:40

0 Answers0