日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

笔记|matplotlib 技巧|使用 gricspec 实现的不同大小子图

發(fā)布時(shí)間:2024/3/13 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 笔记|matplotlib 技巧|使用 gricspec 实现的不同大小子图 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

matplotlib.gridspec.GridSpec

matplotlib 官方文檔:https://matplotlib.org/stable/api/_as_gen/matplotlib.gridspec.GridSpec.html#matplotlib.gridspec.GridSpec

matplotlib 源碼地址:https://github.com/matplotlib/matplotlib/blob/v3.7.1/lib/matplotlib/gridspec.py#L319-L472

參數(shù)列表

nrows, ncols : int —— 行數(shù)和列數(shù)

The number of rows and columns of the grid.

figure : Figure, optional —— 在指定 figure 中構(gòu)建

Only used for constrained layout to create a proper layoutgrid.

left, right, top, bottom : float, optional —— 上下左右邊界位置(用于設(shè)置邊距)

Extent of the subplots as a fraction of figure width or height. Left cannot be larger than right, and bottom cannot be larger than top. If not given, the values will be inferred from a figure or rcParams at draw time. See also GridSpec.get_subplot_params.

wspace : float, optional —— 子圖的橫向間距

The amount of width reserved for space between subplots, expressed as a fraction of the average axis width. If not given, the values will be inferred from a figure or rcParams when necessary. See also GridSpec.get_subplot_params.

hspace : float, optional —— 子圖的縱向間距

The amount of height reserved for space between subplots, expressed as a fraction of the average axis height. If not given, the values will be inferred from a figure or rcParams when necessary. See also GridSpec.get_subplot_params.

width_ratios : array-like of length ncols, optional —— 每一個(gè)子圖的寬度比值

Defines the relative widths of the columns. Each column gets a relative width of width_ratios[i] / sum(width_ratios). If not given, all columns will have the same width.

height_ratios : array-like of length nrows, optional —— 每一個(gè)子圖的高度比值

Defines the relative heights of the rows. Each row gets a relative height of height_ratios[i] / sum(height_ratios). If not given, all rows will have the same height.

樣例

我們使用繪制 “散點(diǎn)圖 + 雙軸直方圖” 的官方樣例來(lái)了解 gridspec 中各個(gè)參數(shù)的用途:

matplotlib 官方樣例:https://matplotlib.org/stable/gallery/lines_bars_and_markers/scatter_hist.html

import numpy as np import matplotlib.pyplot as plt# 構(gòu)造樣例數(shù)據(jù) x = np.random.randn(1000) y = x ** 2 - 3 + np.random.randn(1000)def scatter_hist(x, y, ax, ax_histx, ax_histy):# 關(guān)閉 x 軸直方圖的 x 軸刻度 + 關(guān)閉 y 軸直方圖的 y 軸刻度ax_histx.tick_params(axis="x", labelbottom=False)ax_histy.tick_params(axis="y", labelleft=False)# 在 ax 軸上繪制散點(diǎn)圖ax.scatter(x, y)# 計(jì)算直方圖中桶的邊界binwidth = 0.25xymax = max(np.max(np.abs(x)), np.max(np.abs(y)))lim = (int(xymax/binwidth) + 1) * binwidthbins = np.arange(-lim, lim + binwidth, binwidth)# 在 ax_histx 和 ax_histy 上繪制兩個(gè)直方圖ax_histx.hist(x, bins=bins)ax_histy.hist(y, bins=bins, orientation='horizontal')

樣例 1:原官方案例

# 初始化正方形的 figure fig = plt.figure(figsize=(6, 6))# 構(gòu)造 gridspec 對(duì)象 gs = fig.add_gridspec(2, 2, width_ratios=(4, 1), height_ratios=(1, 4),left=0.1, right=0.9, bottom=0.1, top=0.9,wspace=0.05, hspace=0.05)# 構(gòu)造 3 個(gè)圖的 ax 對(duì)象 ax = fig.add_subplot(gs[1, 0]) ax_histx = fig.add_subplot(gs[0, 0], sharex=ax) ax_histy = fig.add_subplot(gs[1, 1], sharey=ax)# 調(diào)用畫(huà)圖方法 scatter_hist(x, y, ax, ax_histx, ax_histy)

樣例 2:調(diào)整 left、right、bottom、top

將樣例 1 中構(gòu)造 gridspec 對(duì)象的語(yǔ)句修改如下:

gs = fig.add_gridspec(2, 2, width_ratios=(4, 1), height_ratios=(1, 4),left=0.0, right=1.0, bottom=0.0, top=1.0,wspace=0.05, hspace=0.05)

可以看到,left、right、bottom、top 四個(gè)參數(shù)為子圖邊界相較于整個(gè)畫(huà)布的位置,畫(huà)布左側(cè)和上方邊界是 0,右側(cè)和下方邊界是 1。這個(gè)配置只考慮了子圖的邊界在畫(huà)布中的位置,而沒(méi)有考慮坐標(biāo)刻度的位置。

樣例 3:調(diào)整 width_ratios 和 height_ratios

將樣例 1 中構(gòu)造 gridspec 對(duì)象的語(yǔ)句修改如下:

gs = fig.add_gridspec(2, 2, width_ratios=(6, 1), height_ratios=(1, 6),left=0.1, right=0.9, bottom=0.1, top=0.9,wspace=0.05, hspace=0.05)

因?yàn)槲覀冋{(diào)大了第一列和第二行的寬度,所以實(shí)際上也就縮小了第二列和第一行的寬表。

樣例 4:調(diào)整 wspace 和 hspace

將樣例 1 中構(gòu)造 gridspec 對(duì)象的語(yǔ)句修改如下:

gs = fig.add_gridspec(2, 2, width_ratios=(4, 1), height_ratios=(1, 4),left=0.1, right=0.9, bottom=0.1, top=0.9,wspace=1, hspace=1)

可以看到,調(diào)大了 wspace 和 hsapce 后圖的間距增大,但 wspace 和 hspace 的單位與 left、right、bottom 和 top 是不一致的。

總結(jié)

以上是生活随笔為你收集整理的笔记|matplotlib 技巧|使用 gricspec 实现的不同大小子图的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产精品久久久久久久久久免费看 | 91黄色国产| 亚洲综合色小说 | 欧美aⅴ视频 | 亚洲影视一区二区三区 | 波多野结衣视频观看 | 日韩欧美国产中文字幕 | 日韩伦理一区二区 | 亚洲免费三区 | 欧美黑人一级 | 双性受孕h堵精大肚生子 | 国产高潮国产高潮久久久91 | 69视频在线 | 国产欧美一区二区精品性色99 | 日韩精品极品视频 | av自拍偷拍 | 亚洲欧美日韩一区二区三区在线观看 | 亚洲精品一区在线观看 | av在线a | 日日草夜夜草 | 欧美一区二区视频 | 人人爽人人爽人人爽 | 巨物撞击尤物少妇呻吟 | 极品销魂美女一区二区三区 | 久久密av| 亚洲国产专区 | 国产成人一区二区三区小说 | 岳睡了我中文字幕日本 | 国产第三页 | 免费视频a| 国产亚洲精品网站 | 欧美激情黑人 | 久久中出 | 在线天堂网 | 成人国产三级 | 风流还珠之乱淫h文 | 亚洲欧美偷拍一区 | 粉嫩小箩莉奶水四溅在线观看 | 日韩在线视频播放 | 国产91区| 精品国产成人 | 国产成人愉拍精品久久 | 色呦呦网站在线观看 | 国产三级a | 黑人一级女人全片 | 国产成人综合欧美精品久久 | 日韩成人av一区二区 | 玉蒲团在线 | 波多野结衣一区二区三区中文字幕 | 浮力影院国产第一页 | 日本少妇高潮 | 男人操女人逼逼视频 | 亚洲精品久久久久久久久久久 | 夜夜撸影院 | 欧美在线另类 | 亚洲中文无码av在线 | 久久久久久久久久影视 | 免费日韩一区二区 | 西西4444www大胆无码 | 96精品视频在线观看 | 一亲二脱三插 | 亚洲精品视频国产 | 成人欧美一级特黄 | 精品人妻在线视频 | 大地资源高清播放在线观看 | 欧美激情国产日韩精品一区18 | 成人av网站大全 | 日本少妇吞精囗交 | 性活交片大全免费看 | 精品国产乱码久久久久久久软件 | 久久大综合 | 国产精品久久二区 | 日本japanese乳偷乱熟 | 67194在线免费观看 | 国产a级片免费看 | 亚洲综合久久婷婷 | 日本三级中文字幕在线观看 | 高清日韩欧美 | 国产免费观看久久黄av片 | 人人干人人做 | 国产情侣av自拍 | 精品乱码一区二区三区 | 中文字幕乱码视频 | 偷拍亚洲视频 | 老司机狠狠爱 | 欧美爱爱免费视频 | 日本最黄网站 | 午夜福利电影 | 冲田杏梨一区二区三区 | 日韩精品一区在线视频 | 亚洲中文字幕一区在线 | 嫩草影院中文字幕 | 亚洲天堂精品在线观看 | 色在线免费观看 | 在线观看不卡av | 日本三级免费网站 | 亚洲第一视频在线播放 | 97久久久久久 | 国产aⅴ精品 |