A
A
argeo052021-12-29 03:11:48
Python
argeo05, 2021-12-29 03:11:48

How to plot dynamic plot in matplotlib?

There is a code for dice rolls, how to implement it so that the graph is updated after a certain number of rolls (updated)

import matplotlib.pyplot as plt
from random import randrange

score = [1, 2, 3, 4, 5, 6]
counts = [34, 25, 43, 31, 17, 53]
fig = plt.bar(score, counts)
plt.title("Броски кубика")
plt.xlabel("очки")
plt.ylabel("Количество")
plt.show()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2021-12-29
@res2001

Enable plt.ion() interactive mode and update when needed. In this case, plt.show() returns immediately after rendering, rather than waiting until you close the window.
To pause the program so that the window doesn't stop responding to user input, use plt.pause().
At the next redrawing, it is necessary that the window (fig) remains the same, otherwise there will be blinking due to the constant deletion of the old / creation of a new window, the old contents of the window can be deleted using fig.clear ().
In general, matplotlib has good documentation and many examples.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question