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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

subplots_adjust()函数--matplotlib

發布時間:2024/3/13 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 subplots_adjust()函数--matplotlib 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1. 函數功能

調整子區的展現效果

2. 函數語法

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

3. 函數參數與示例

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

3.1 hsapce

import matplotlib.pyplot as plt import numpy as np import matplotlib as mplmpl.rcParams['font.sans-serif'] = ['KaiTi'] mpl.rcParams['axes.unicode_minus'] = Falsex = np.linspace(0, 2 * np.pi, 500) y1 = np.sin(x) * np.cos(x) y2 = np.exp(-x) y3 = np.sqrt(x) y4 = x / 4fig, 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()


對于本例中的圖形,所有圖形共享x軸,則圖形與圖形之間不需要空隙,垂直方向的空隙可以通過hspace=0,實現消除

import matplotlib.pyplot as plt import numpy as np import matplotlib as mplmpl.rcParams['font.sans-serif'] = ['KaiTi'] mpl.rcParams['axes.unicode_minus'] = Falsex = np.linspace(0, 2 * np.pi, 500) y1 = np.sin(x) * np.cos(x) y2 = np.exp(-x) y3 = np.sqrt(x) y4 = x / 4fig, 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 mplmpl.rcParams['font.sans-serif'] = ['KaiTi'] mpl.rcParams['axes.unicode_minus'] = Falsex = np.linspace(0, 2 * np.pi, 500) y1 = np.sin(x) * np.cos(x) y2 = np.exp(-x) y3 = np.sqrt(x) y4 = x / 4fig, 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()

總結

以上是生活随笔為你收集整理的subplots_adjust()函数--matplotlib的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。