subplots_adjust()函数--matplotlib
生活随笔
收集整理的這篇文章主要介紹了
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,實現消除
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的全部內容,希望文章能夠幫你解決所遇到的問題。