Matplotlib.figure.Figure.set_constrained_layout () в Python
Matplotlib - это библиотека на Python, которая является численно-математическим расширением библиотеки NumPy. Модуль Figure предоставляет Художника верхнего уровня, Figure, который содержит все элементы сюжета. Этот модуль используется для управления интервалом по умолчанию для подзаголовков и контейнера верхнего уровня для всех элементов графика.
matplotlib.figure.Figure.set_constrained_layout () метод
Модуль фигуры метода set_constrained_layout () библиотеки matplotlib используется для установки, будет ли использоваться constrained_layout при рисовании.
Syntax: set_constrained_layout(self, constrained)
Parameters: This method accept the following parameters that are discussed below:
- constrained: This parameter is the bool or dict or None.
Returns: This method returns the axes.
Примеры ниже иллюстрируют функцию matplotlib.figure.Figure.set_constrained_layout () в matplotlib.figure:
Example 1:
# Implementation of matplotlib functionimport numpy as npimport matplotlib.pyplot as plt fig, ax = plt.subplots(constrained_layout = True)x = np.arange(0.02, 1, 0.02) np.random.seed(19680801)y = np.random.randn(len(x)) ** 2 ax.loglog(x, y) ax.set_xlabel("f [Hz]")ax.set_ylabel("PSD")ax.set_title("Random spectrum") def forward(x): return 1 / x def inverse(x): return 1 / x fig.set_constrained_layout(True) fig.suptitle("""matplotlib.figure.Figure.set_constrained_layout()function Example
""", fontweight ="bold") plt.show() |
Выход:
Example 2:
# Implementation of matplotlib functionimport matplotlibimport matplotlib.pyplot as pltimport matplotlib.gridspec as gridspec fig = plt.figure()gs = fig.add_gridspec(3, 3)ax = fig.add_subplot(gs[0, :]) ax.set_title("gs[0, :]")ax2 = fig.add_subplot(gs[1, :-1])ax2.set_title("gs[1, :-1]") fig.set_constrained_layout(False) fig.suptitle("""matplotlib.figure.Figure.set_constrained_layout()function Example
""", fontweight ="bold") plt.show() |
Выход:
Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.
Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.