日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

subplots_adjust()函數(shù)--matplotlib

作者:牽牛花主人 更新時(shí)間: 2022-10-29 編程語言

1. 函數(shù)功能

調(diào)整子區(qū)的展現(xiàn)效果

2. 函數(shù)語法

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

3. 函數(shù)參數(shù)與示例

參數(shù) 含義
left 可選參數(shù),浮點(diǎn)數(shù);子區(qū)左邊的位置,默認(rèn)為 0.125,以畫布figure為參考系
right 可選參數(shù),浮點(diǎn)數(shù);子區(qū)右邊的位置 ,默認(rèn)為 0.9,以畫布figure為參考系
bottom 可選參數(shù),浮點(diǎn)數(shù);子區(qū)底邊的位置,默認(rèn)為 0.11,以畫布figure為參考系
top 可選參數(shù),浮點(diǎn)數(shù);子區(qū)頂邊的位置,默認(rèn)為 0.88,以畫布figure為參考系
wspace 可選參數(shù),浮點(diǎn)數(shù);子區(qū)之間的空白寬度,默認(rèn)為 0.2,以繪圖區(qū)的平均寬度為參考
hspace 可選參數(shù),浮點(diǎn)數(shù);子區(qū)之間的空白高度,默認(rèn)為 0.2,以繪圖區(qū)的平均寬度為參考

3.1 hsapce

import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl

mpl.rcParams['font.sans-serif'] = ['KaiTi']
mpl.rcParams['axes.unicode_minus'] = False

x = np.linspace(0, 2 * np.pi, 500)
y1 = np.sin(x) * np.cos(x)
y2 = np.exp(-x)
y3 = np.sqrt(x)
y4 = x / 4

fig, ax = plt.subplots(4, 1, facecolor='beige', sharex=True,
                       subplot_kw=dict(facecolor='seashell'))
ax[0].plot(x, y1, c='r', lw=2)
ax[1].plot(x, y2, c='y', ls="--")
ax[2].plot(x, y3, c='g', ls=":")
ax[3].plot(x, y4, c='m', ls='-.', lw=2)

plt.show()

在這里插入圖片描述
對(duì)于本例中的圖形,所有圖形共享x軸,則圖形與圖形之間不需要空隙,垂直方向的空隙可以通過hspace=0,實(shí)現(xiàn)消除

import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl

mpl.rcParams['font.sans-serif'] = ['KaiTi']
mpl.rcParams['axes.unicode_minus'] = False

x = np.linspace(0, 2 * np.pi, 500)
y1 = np.sin(x) * np.cos(x)
y2 = np.exp(-x)
y3 = np.sqrt(x)
y4 = x / 4

fig, ax = plt.subplots(4, 1, facecolor='beige', sharex=True,
                       subplot_kw=dict(facecolor='seashell'))

fig.subplots_adjust(hspace=0)

ax[0].plot(x, y1, c='r', lw=2)
ax[1].plot(x, y2, c='y', ls="--")
ax[2].plot(x, y3, c='g', ls=":")
ax[3].plot(x, y4, c='m', ls='-.', lw=2)

plt.show()

在這里插入圖片描述

3.2 left right bottom top

import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl

mpl.rcParams['font.sans-serif'] = ['KaiTi']
mpl.rcParams['axes.unicode_minus'] = False

x = np.linspace(0, 2 * np.pi, 500)
y1 = np.sin(x) * np.cos(x)
y2 = np.exp(-x)
y3 = np.sqrt(x)
y4 = x / 4

fig, ax = plt.subplots(4, 1, facecolor='beige', sharex=True,
                       subplot_kw=dict(facecolor='seashell'))

fig.subplots_adjust(left=0.05, right=0.98, bottom=0.05,
                    top=0.95, hspace=0)

ax[0].plot(x, y1, c='r', lw=2)
ax[1].plot(x, y2, c='y', ls="--")
ax[2].plot(x, y3, c='g', ls=":")
ax[3].plot(x, y4, c='m', ls='-.', lw=2)

plt.show()

在這里插入圖片描述

原文鏈接:https://blog.csdn.net/chongbaikaishi/article/details/127578822

欄目分類
最近更新