Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack.
matplotlib.gridspec.GridSpec class is used to specify the geometry of the grid to place a subplot. For this, to work the number of rows and columns must be set. Optionally, tuning of subplot layout parameters can be also done.
Syntax: class matplotlib.gridspec.GridSpec(nrows, ncols, figure=None, left=None, bottom=None, right=None, top=None, wspace=None, hspace=None, width_ratios=None, height_ratios=None)
- nrows: It is an integer representing the number of rows in the grid.
- ncols: It is an integer representing the number of columns in the grid.
- figure: It is an optional parameter used to draw figures.
- left, right, top, bottom: These are optional parameters used to define the extent of the subplots as fraction of figure width or height.
- wspase: It is an optional float argument used to reserve the width space between subplots.
- hspace: It is an optional float argument used to reserve the height space between subplots.
- width_ratios: It is an optional parameter that represents the width ratios of the columns.
- height_ratios: It is an optional parameter that represents the width ratios of the rows.
Methods of the class:
- get_subplot_params(self, figure=None): It returns a dictionary of subplot layout parameters. unless a figure attribute is set, the default parameter is from rcParams.
- ight_layout(self, figure, renderer=None, pad=1.08, h_pad=None, w_pad=None, rect=None): It is used to give specific padding to adjust the subplots. Here pad is a float value that sets padding between figure edge and the subplot edges as a fraction of the font size. The h_pad and w_pad are optional argument used to set padding between adjacent subplots. Also rect is used to normalize figure coordinates of a rectange that inclues all the subplot area. its default is (0, 0, 1, 1). It is a tuple of 4 floats.
- Class or Static Variables in Python
- String Template Class in Python
- Changing Class Members in Python
- Object Oriented Programming in Python | Set 1 (Class, Object and Members)
- class method vs static method in Python
- First Class functions in Python
- Violinplot in Python using axes class of Matplotlib
- Class and Instance Attributes in Python
- Matplotlib.ticker.MultipleLocator Class in Python
- CBSE Class 12 | Computer Science - Python Syllabus
- CBSE Class 11 | Computer Science - Python Syllabus
- Matplotlib.patches.CirclePolygon class in Python
- Class as decorator in python
- Python | Avoiding class data shared among the instances
- Python | Using variable outside and inside the class and method
- self in Python class
- Python Tkinter | Create different type of lines using Canvas class
- Python Tkinter | Create different shapes using Canvas class
- How to create a list of object in Python class
- rangev2 - A new version of Python range class
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.