(TIL) Matplotlib: Clearing a figure

less than 1 minute read

import matplotlib.pyplot as plt

# Clear an axis, i.e. the currently active axis in the current figure.
# This leaves the other axes untouched.
plt.cla()

# Clear the entire current figure with all its axes.
# This leaves the window opened, such that it may be reused for other plots.
plt.clf()

# Close a window, which will be the current window, if not specified otherwise.
plt.close()

Via StackOverflow.

Comments