- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I dynamically update my Matplotlib figure as the data file changes?
To update a Matplotlib figure as the data file changes, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Initialize variables m and n, to get a set of subplots.
- Create a list of colors, to plot color dynamically.
- Plot dynamic data points using plot() method with random data points.
- To display the figure, use show() method.
Example
import numpy as np import matplotlib.pyplot as plt import random plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True m = 2 n = 4 fix, axes = plt.subplots(nrows=m, ncols=n) hexadecimal_alphabets = '0123456789ABCDEF' color = ["#" + ''.join([random.choice(hexadecimal_alphabets) for j in range(6)]) for i in range(m*n)] for i in range(m): for j in range(n): axes[i][j].clear() axes[i][j].plot(np.random.rand(10), np.random.rand(10), color=color[100 % np.random.randint(1, len(color))]) plt.pause(0.1) plt.show()
Output
- Related Articles
- Save figure as file from iPython notebook using Matplotlib
- How can I get the color of the last figure in Matplotlib?
- How can I add textures to my bars and wedges in Matplotlib?
- How I can dynamically import Python module?
- Should I always put my JavaScript file in the head tag of my HTML file?
- How can I attach a pyplot function to a figure instance? (Matplotlib)
- How do I let my Matplotlib plot go beyond the axes?
- How can I increase my monthly savings?
- How can I curb my shopping addiction?
- How can I improve my spoken English?
- How can I get my invention patented?
- How can I get the output of a Matplotlib plot as an SVG?
- How can I dynamically set the position of view in android?
- How to import local json file data to my JavaScript variable?
- How should I pass a matplotlib object through a function; as Axis, Axes or Figure?

Advertisements