
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to manipulate figures while a script is running in Python Matplotlib?
To manipulate figures while a script is running in Python, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Create a new figure or activate an existing figure using figure() method.
- Get the current axis, ax, and show the current figure.
- Manipulate the script using plt.pause() method, before the final plot.
- Plot the line using plot() method.
- To display the figure, use show() method.
Example
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.gca() fig.show() for i in range(20): ax.plot(np.random.randn(10, 1), ls='-') fig.canvas.draw() plt.pause(0.1) plt.close(fig) plt.plot([1, -2, 3, 5, 3, 1, 0]) plt.show()
Output
- Related Articles
- How to give manual input from user while running Selenium IDE script?
- How do I check what version of Python is running my script?
- How do you dynamically add Python modules to a package while your programming is running?
- How to customize spines of Matplotlib figures?
- How to show two figures using Matplotlib?
- Drawing multiple figures in parallel in Python with Matplotlib
- How to check Syntax of a Bash Script without running it in Linux?
- How can I show figures separately in Matplotlib?
- How to save figures to pdf as raster images in Matplotlib?
- How to check the syntax of a Bash script without running it in Linux?
- Flushing all current figures in matplotlib
- How to delete the actives while running a loop in the internal table?
- Is there a need to import Java.lang package while running Java programs?
- How to deal with NaN values while plotting a boxplot using Python Matplotlib?
- Ensure Only One Instance of a Bash Script Is Running on Linux

Advertisements