How to use subplots_tool() method to set the spacing between subplots In Matplotlib
This method launches a subplot tool window for a figure. It provides an interactive method for the user to drag the bar in the subplot_tool to change the subplots’ layout.
Python3
# set the spacing between subplots plt.subplot_tool() plt.show() |
Output:
How to set the spacing between subplots in Matplotlib in Python?
In this article, we will see how to set the spacing between subplots in Matplotlib in Python. Let’s discuss some concepts :
- Matplotlib : 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. It was introduced by John Hunter in the year 2002.
- Subplots : The subplots() function in pyplot module of matplotlib library is used to create a figure and a set of subplots. Subplots are required when we want to show two or more plots in same figure.
Here, first we will see why setting of space is required.
Python3
# importing packages import numpy as np import matplotlib.pyplot as plt # create data x = np.array([ 1 , 2 , 3 , 4 , 5 ]) # making subplots fig, ax = plt.subplots( 2 , 2 ) # set data with subplots and plot ax[ 0 , 0 ].plot(x, x) ax[ 0 , 1 ].plot(x, x * 2 ) ax[ 1 , 0 ].plot(x, x * x) ax[ 1 , 1 ].plot(x, x * x * x) plt.show() |
Output: