Ketan Ramteke
Ketan Ramteke

Reputation: 10655

Plotting live pie-chart using matplotlib pyplot

Code:

import matplotlib.pyplot as plt
from time import sleep
for i in range(100):
    plt.pie([100-i,i])
    sleep(1)
    plt.show()

enter image description here

Problem with my code:

What I want to do:

thank you.

Upvotes: 3

Views: 1076

Answers (2)

Ketan Ramteke
Ketan Ramteke

Reputation: 10655

Fixed it.

import matplotlib.pyplot as plt
from time import sleep
for i in range(100):
   plt.pie([100-i, i])
   plt.pause(.001)
   plt.draw()
   sleep(1)

plt.show() is blocking function so instead used plt.draw() along with plt.pause() and now it's working as intended.

Upvotes: 0

onno
onno

Reputation: 979

add plt.close() to your for-loop

import matplotlib.pyplot as plt
from time import sleep
for i in range(100):
    plt.pie([100-i,i])
    sleep(1)
    plt.show()
    plt.close()

Upvotes: 1

Related Questions