How can I show figures separately in Matplotlib?
Last Updated :
23 Jul, 2025
In data visualization, it’s common to create multiple plots or figures for comparison, but sometimes you may need to display each plot separately. In Matplotlib, this can be easily achieved by creating and managing multiple figure objects. Most common method to create a new figure, or activate an existing figure, we use the figure() method. Let's implement the methods with examples:
Method 1: Using plt.figure()
to Create Separate Figures
The plt.figure()
function is essential in creating new figure objects in Matplotlib. By calling this function before plotting, you specify that all subsequent plotting commands should belong to the new figure. This enables you to separate your plots, ensuring each one appears in its own window. Using plt.figure()
provides control over which figure you’re working with. It’s the most straightforward and intuitive method for beginners.
Python
import matplotlib.pyplot as plt
import numpy as np
# First figure
plt.figure(1)
x = np.linspace(0, 10, 100)
y1 = np.sin(x)
plt.plot(x, y1)
plt.title("I am Figure 1")
plt.show()
# Second figure
plt.figure(2)
y2 = np.cos(x)
plt.plot(x, y2)
plt.title("I am Figure 2")
plt.show()
Output:
show figures separately in MatplotlibMethod 2: Calling plt.show()
After Each Figure
After creating separate figures with plt.figure()
, the plt.show()
function is used to display each figure independently. If you call plt.show()
after plotting each figure, Matplotlib will display them sequentially as separate entities.
Python
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y1 = np.sin(x)
y2 = np.cos(x)
# First figure: Plotting the sine wave
plt.figure(1)
plt.plot(x, y1)
plt.title("Sine Wave - Figure 1")
plt.show()
# Second figure: Plotting the cosine wave
plt.figure(2)
plt.plot(x, y2)
plt.title("Cosine Wave - Figure 2")
plt.show()
Output:
show figures separately in MatplotlibMethod 3: Using plt.subplots()
for Multiple Axes in One Figure
While not strictly for creating separate figures, plt.subplots(
)
allows you to create multiple axes (subplots) within a single figure. This is useful when you want to compare data side by side but still prefer to work within a single figure window.
Python
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y1 = np.sin(x)
y2 = np.cos(x)
fig, (ax1, ax2) = plt.subplots(1, 2)
ax1.plot(x, y1)
ax1.set_title("Sine Wave")
ax2.plot(x, y2)
ax2.set_title("Cosine Wave")
plt.show()
Output:
or Multiple Axes in One Figure