Matplotlib Figure Class
In this tutorial, we will cover the Figure class in the matplotlib library.
As we all know that matplotlib is a python library used to create visualization which is also a numerical extension of Numpy library.
The matplotlib library contains a Figure class in the
For all plotting elements figure class is mainly a top-level container.
To instantiate the figure object you just need to call the
figure()function of the pyplot module ( It is a state-based interface to matplotlib)
With the help of pyplot one can easily create histograms, violin plot, contour plot, 3D plots, and many more.
We can also extend the Figure class and create a custom class based on our requirements. (Python Inheritance)
To create a new figure the
figure() function of the pyplot module is used in the matplotlib library.
The syntax to use this function is given below:
matplotlib.pyplot.figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, clear, **kwargs)
Let us discuss the parameters of the
The default value of this parameter is None. You can provide this parameter and also the figure with this id already exists.
This is used to indicate the width and height in pixels.
This parameter is used to indicate the resolution of the figure. The default value is None.
This parameter is used to indicate the background color.
This parameter is used to indicate the border color.
If you do not want to draw the frame of the figure, this option is used. The default value of this parameter is true, which means by default the frame is drawn.
This parameter mainly uses a custom Figure instance.
The default value is false. If the value of this parameter is true and the figure already exists, then it is cleared.
This method returns the Figure instance which is also passed to
new_figure_manager in the backend.
Time for Example:
Let us discuss this function with the help of an example given below:
In the above code example, we have created a new class MyFigure inheriting the original Figure class.
In this tutorial, we covered the Figure class available in the
matplotlib.figure module. We also learned about the
figure() function which is very useful.