Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  • Whenever the values of plt.pie() changes and the pie chart are plotted then execution of for loop seems to be halted and I have to close the pie chart window to resume to the execution of for loop.

What I want to do:

  • plt.pie() display live changes in its values without halting for loop's execution.

thank you.

like image 651
Ketan Ramteke Avatar asked Mar 07 '26 22:03

Ketan Ramteke


1 Answers

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()
like image 127
onno Avatar answered Mar 09 '26 12:03

onno



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!