Matplotlib.figure.Figure.subplots_adjust () в Python

Опубликовано: 23 Марта, 2022

Matplotlib - это библиотека на Python, которая является численно-математическим расширением библиотеки NumPy. Модуль Figure предоставляет Художника верхнего уровня, Figure, который содержит все элементы сюжета. Этот модуль используется для управления интервалом по умолчанию для подзаголовков и контейнера верхнего уровня для всех элементов графика.

matplotlib.figure.Figure.subplots_adjust () метод

Модуль рисунка метода subplots_adjust () библиотеки matplotlib используется для обновления SubplotParams с помощью kwargs.

Syntax: subplots_adjust(self, left=None, bottom=None, right=None, top=None, wspace=None, hspace=None)

Parameters: This method accept the following parameters that are discussed below:

  • left : This parameter is the left side of the subplots of the figure.
  • right : This parameter is the right side of the subplots of the figure.
  • bottom : This parameter is the bottom of the subplots of the figure.
  • top : This parameter is the top of the subplots of the figure.
  • wspace : This parameter is the amount of width reserved for space between subplots expressed as a fraction of the average axis width.
  • hspace : This parameter is the amount of height reserved for space between subplots expressed as a fraction of the average axis height.

Returns: This method does not returns any value.

Примеры ниже иллюстрируют функцию matplotlib.figure.Figure.subplots_adjust () в matplotlib.figure:

Example 1:

# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
   
  
x = [1, 2, 3, 4]
y = [1, 4, 9, 16]
   
fig = plt.figure()
axs = fig.subplots()
  
axs.plot(x, y)
  
fig.subplots_adjust(bottom = 0.15)
  
fig.suptitle("""matplotlib.figure.Figure.subplots_adjust()
function Example """, fontweight ="bold") 
  
fig.show() 

Выход:

Example 2:

# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import TextBox
  
  
fig, ax = plt.subplots()
fig.subplots_adjust(bottom = 0.2)
  
t = np.arange(-2.0, 2.0, 0.001)
s = np.sin(t)+np.cos(2 * t)
  
initial_text = "sin(t) + cos(2t)"
l, = ax.plot(t, s, lw = 2)
   
   
def submit(text):
    ydata = eval(text)
    l.set_ydata(ydata)
    ax.set_ylim(np.min(ydata), np.max(ydata))
    plt.draw()
   
axbox = plt.axes([0.4, 0.05, 0.3, 0.075])
  
text_box = TextBox(axbox, "Formula Used : ",
                   initial = initial_text)
text_box.on_submit(submit)
  
fig.suptitle("""matplotlib.figure.Figure.subplots_adjust()
function Example """, fontweight ="bold") 
  
fig.show() 

Выход:

Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.

Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.