1

I am doing my first matplotlib animation graph. and It's not working.please someone explain me,why??

import matplotlib.animation as animation
import matplotlib.pyplot as plt
import numpy as np

n = 100
X = np.random.randn(n)

def update(curr):
    if curr == n:
        a.event_source.stop()
    plt.cla()
    bins = np.arange(-4,4, 0.5)
    plt.hist(X[:curr], bin=bins)
    plt.axis([-4,4,0,30])
    plt.annotate("n={}".format(curr),(3,27))
  

fig = plt.figure()
a = animation.FuncAnimation(fig, update, interval=100)

P.S. I am coding on jupyter notebook

5
  • have you tried plt.show()? Commented Jul 25, 2020 at 15:48
  • yes. tried and not working. Commented Jul 25, 2020 at 15:56
  • can you please give reproducible code full? the curr variable is not recognized. Commented Jul 25, 2020 at 15:58
  • Actually, I am doing a coursera course on data visualization in that the prof told, corr is a recursive variable which will automatically update after each time function runs. Commented Jul 25, 2020 at 16:04
  • 1
    Oh, I see. I would suggest you ask this on the coursera forum then. Commented Jul 25, 2020 at 16:06

1 Answer 1

1

I got my answer. It's a typo in plt.hist call. The parameter is bins not bin.
plt.hist(X[:curr], bins=bins)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.