![]() |
VOOZH | about |
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:
plt.figure() to Create Separate FiguresThe 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.
Output:
plt.show() After Each FigureAfter 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.
Output:
plt.subplots() for Multiple Axes in One FigureWhile 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.
Output: