In [24]:
import matplotlib.pyplot as plt
import random
import time

%matplotlib nbagg

# fig = plt.figure()
# ax = fig.add_subplot(1, 1, 1)
# circ = plt.Circle((0, 0), radius=1, edgecolor='b', facecolor='None')
# ax.add_patch(circ)
# plt.axis('equal')
# plt.axis([0, 1, 0, 1])
# plt.ion()

NB_POINTS = 10**5

def in_circle(x, y):
    return x**2 + y**2 < 1

def compute_pi(cycles):
    inside = 0
    for _ in range(cycles):
        point = [random.random(), random.random()]
        inside += 1 if in_circle(*point) else 0
#         plt.scatter(point[0], point[1])
#         plt.pause(0.05)
    return (inside / cycles) * 4

print(compute_pi(NB_POINTS))
# plt.show()


3.13812

In [1]:
import numpy as np
import matplotlib.pyplot as plt

%matplotlib nbagg

plt.axis([0, 1, 0, 1])
fig=plt.figure()
plt.ion()

for i in range(100):
    y = np.random.random()
    plt.scatter(i, y)
    plt.show()
    plt.pause(0.0001)


/home/tony/anaconda3/lib/python3.5/site-packages/matplotlib/backend_bases.py:2437: MatplotlibDeprecationWarning: Using default event loop until function specific to this GUI is implemented
  warnings.warn(str, mplDeprecation)
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-1-7f4e34140d3b> in <module>()
     12     plt.scatter(i, y)
     13     plt.show()
---> 14     plt.pause(0.0001)

/home/tony/anaconda3/lib/python3.5/site-packages/matplotlib/pyplot.py in pause(interval)
    289                 canvas.draw()
    290             show(block=False)
--> 291             canvas.start_event_loop(interval)
    292             return
    293 

/home/tony/anaconda3/lib/python3.5/site-packages/matplotlib/backends/backend_nbagg.py in start_event_loop(self, timeout)
    192 
    193     def start_event_loop(self, timeout):
--> 194         FigureCanvasBase.start_event_loop_default(self, timeout)
    195 
    196     def stop_event_loop(self):

/home/tony/anaconda3/lib/python3.5/site-packages/matplotlib/backend_bases.py in start_event_loop_default(self, timeout)
   2443         self._looping = True
   2444         while self._looping and counter * timestep < timeout:
-> 2445             self.flush_events()
   2446             time.sleep(timestep)
   2447             counter += 1

/home/tony/anaconda3/lib/python3.5/site-packages/matplotlib/backend_bases.py in flush_events(self)
   2388         backends with GUIs.
   2389         """
-> 2390         raise NotImplementedError
   2391 
   2392     def start_event_loop(self, timeout):

NotImplementedError: 

In [ ]: