日韩性视频-久久久蜜桃-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ò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 亚洲成人免费视频 | 国产又粗又长又大视频 | 成人av高清在线观看 | 林雅儿欧洲留学恋爱日记在线 | 日韩视频精品在线 | 天天插天天透 | 欧美中文字幕在线 | 无遮挡在线观看 | 波多野结衣视频免费看 | 蜜臀999 | 日女人网站 | 久久另类ts人妖一区二区 | 69视频一区二区 | av在线大全 | www四虎影院 | 久久久www成人免费无遮挡大片 | 国产在线观看免费视频软件 | 少妇扒开粉嫩小泬视频 | 中国女人内谢69xxxx免费视频 | 国产日本亚洲 | 依人成人综合网 | 欧美国产精品一区二区三区 | 国产精品无遮挡 | 亚洲精品无码专区 | 国产婷婷色 | 亚洲色图14p| 日本免费网站视频 | 欧美视频免费看 | 国产xxxx做受性欧美88 | 亚洲区一区二区三区 | 四虎影院新网址 | 亚洲午夜在线观看 | 国产欧美日韩专区 | 中文字幕久久av | 天天干导航 | 日韩网站免费观看 | 在线免费一区 | 熊猫成人网 | 乱子伦一区二区三区 | av香蕉| 成人3d动漫一区二区三区 | 久久精品性 | 精品国产一区二区三区在线观看 | 三级视频网 | av中文字幕在线播放 | 黄在线免费观看 | 精品| 蜜臀av性久久久久蜜臀aⅴ麻豆 | 久久免费福利视频 | 亚洲AV成人无码一二三区在线 | 日本黄色网络 | 青青青国内视频在线观看软件 | 欧美少妇一区二区三区 | 国产视频黄 | 人人澡超碰碰97碰碰碰 | 99久久99久久免费精品蜜臀 | 国产探花一区二区 | 狠狠撸狠狠操 | 日一区二区三区 | 最近中文字幕在线中文视频 | 男女av网站| 久久官网 | 凹凸精品一区二区三区 | 中文字幕在线视频免费 | 都市激情亚洲综合 | 欧美精品成人一区二区在线观看 | 日本人六九视频 | 99久久亚洲精品日本无码 | 99久久婷婷国产综合精品青牛牛 | 午夜免费看视频 | 丁香婷婷九月 | 人妖一级片 | 菊肠扩张playh | 欧美日韩在线中文字幕 | 午夜做爰xxxⅹ性高湖视频美国 | 美国黄色网址 | 成人免费毛片免费 | 国产精品igao | 日韩欧美一本 | 99成人精品 | 美女黄18以下禁止观看 | 插久久 | 亚洲中文字幕一区 | 一区二区三区四区在线 | 成人午夜av| 兄弟兄弟全集免费观看 | 看片一区| 国产欧美日韩在线播放 | 欧美精品一区在线 | 日韩一区二区免费在线观看 | 成人国产亚洲 | 精品久久蜜桃 | 美女被啪啪 | 亚洲综合日韩精品欧美综合区 | 亚洲天堂婷婷 | 亚洲人和日本人hd | 99国产精品久久久 | 神马午夜久久 | 99久久99久久精品免费看蜜桃 |