![]() |
VOOZH | about |
Matplotlib close() function in pyplot module of the matplotlib library is used to close a figure window. This function is designed to close a figure window or a set of figure windows. When called without any arguments, it closes the currently active figure. Alternatively, we can pass a figure number or a reference to a figure object as an argument to close a specific figure.
Syntax: matplotlib.pyplot.close(fig=None)
Parameters: This method accept only one parameters.
- fig: This parameter accepts the following values:
- None: This value will close the current figure
- Figure: This value will close the given Figure instance
- int: This value will close a figure number
- str: This value will close a figure name
- 'all':This value will close all figures
Returns: This method does not return any values.
Below are the examples by which we can understand about how to close Matplotlib figure in Python using Matplotlib.pyplot.close() function:
In this example, the code uses Matplotlib to create a 2D plot with two overlaid images. The first image (`Z1`) represents a checkerboard pattern, displayed in binary colors. The second image (`Z2`) is generated using a custom function (`geeks`) and displayed in green with partial transparency. Then using close() function, windows are closed.
Output:
👁 ImageIn this example, the code utilizes Matplotlib to generate a triangular mesh plot with two overlaid images. The first image (Z1) displays a checkerboard pattern, and the second image (Z2) is generated using a custom function. The code also includes a call to plt.close(1) to close the default figure, and it proceeds to create a triangular mesh plot with a color bar using the matplotlib.tri module.