-4

I'm trying to implement an application that plots data in a real time fashion. I have tried some code I found in this question but it doesn't work. The figure plots one result before the for loop and one result when the for loop is done

This is run in Ubuntu, from the Python interpreter.

The code I'm referring to:

import numpy as np
import matplotlib.pyplot as plt

plt.ion()
mu, sigma = 100, 15
fig = plt.figure()
x = mu + sigma*np.random.randn(10000)
n, bins, patches = plt.hist(x, 50, normed=1, facecolor='green', alpha=0.75)
for i in range(50):
    x = mu + sigma*np.random.randn(10000)
    n, bins = np.histogram(x, bins, normed=True)
    for rect,h in zip(patches,n):
        rect.set_height(h)
    fig.canvas.draw()
Community
  • 1
  • 1
evan54
  • 3,585
  • 5
  • 34
  • 61

1 Answers1

0

The problem arises because of the backend. I had Qt4Agg and after changing it to TkAgg it worked.. no idea why Qt4Agg didn't worth though...

to change the backend i had to edit the /etc/matplotlibrc file

EDIT:

found information about Qt4Agg instead of calling draw() it should be paused for as long as required by calling pause(0.001) instead, here it is paused for 1ms.

info on this

https://github.com/matplotlib/matplotlib/issues/177

evan54
  • 3,585
  • 5
  • 34
  • 61