How to Count Number of Data Points?
<p>I have 200 data points scattered from this loop:</p>

<pre><code>import math
plt.figure()

for i in range(200):
    r=random.uniform(-1,1)
    x=random.uniform(-1,1)
    if math.sqrt(x**2+r**2)&lt;1:
        plt.plot(x,r,'r.')
    else:
        plt.plot(x,r,'k.')
redraw()
</code></pre>

<p>So there will be a number of plots that meets the <code>if</code> condition. I want to know the number of those points. What should I do?</p>

<p>You would just need to increment a counter when the condition is met:</p>

<pre><code>import math
plt.figure()

good_samples = 0
for i in range(200):
    r=random.uniform(-1,1)
    x=random.uniform(-1,1)
    if math.sqrt(x**2+r**2)&lt;1:
        plt.plot(x,r,'r.')
        good_samples += 1
    else:
        plt.plot(x,r,'k.')
redraw()
print "Counted {} good samples".format(good_samples)
</code></pre>

python python-2.7