# Seaborn 分布圖
> 原文: [https://pythonbasics.org/seaborn-distplot/](https://pythonbasics.org/seaborn-distplot/)
通過 Seaborn 分布圖,您可以顯示帶有線條的直方圖。 這可以以各種變化形式顯示。 我們將 Seaborn 與 Python 繪圖模塊 Matplotlib 結合使用。
分布圖繪制觀測值的單變量分布。 `distplot()`函數將 Matplotlib `hist`函數與 Seaborn `kdeplot()`和`rugplot()`函數結合在一起。
## 示例
### 分布圖示例
下圖顯示了一個簡單的分布。 它使用`random.randn()`創建隨機值。如果您也手動定義值,它將起作用。
```py
import matplotlib.pyplot as plt
import seaborn as sns, numpy as np
sns.set(rc={"figure.figsize": (8, 4)}); np.random.seed(0)
x = np.random.randn(100)
ax = sns.distplot(x)
plt.show()
```

### 分布圖示例
您可以顯示分布圖的各種變化。 我們使用`pylab`模塊中的`subplot()`方法來一次顯示 4 種變化。
通過更改`distplot()`方法中的參數,您可以創建完全不同的視圖。 您可以使用這些參數來更改顏色,方向等。
```py
import matplotlib.pyplot as plt
import seaborn as sns, numpy as np
from pylab import *
sns.set(rc={"figure.figsize": (8, 4)}); np.random.seed(0)
x = np.random.randn(100)
subplot(2,2,1)
ax = sns.distplot(x)
subplot(2,2,2)
ax = sns.distplot(x, rug=False, hist=False)
subplot(2,2,3)
ax = sns.distplot(x, vertical=True)
subplot(2,2,4)
ax = sns.kdeplot(x, shade=True, color="r")
plt.show()
```

[下載示例](https://gum.co/mpdp)
### Seaborn 分布
您也可以在直方圖中顯示 Seaborn 的標準數據集。這是一個很大的數據集,因此僅占用一列。
```py
import matplotlib.pyplot as plt
import seaborn as sns
titanic=sns.load_dataset('titanic')
age1=titanic['age'].dropna()
sns.distplot(age1)
plt.show()
```

### 分布圖容器
如果您想更改桶的數量或隱藏行,也可以。當調用方法`distplot()`時,您可以傳遞箱數并告訴直線(kde)不可見。
```py
import matplotlib.pyplot as plt
import seaborn as sns
titanic=sns.load_dataset('titanic')
age1=titanic['age'].dropna()
sns.distplot(age1,bins=30,kde=False)
plt.show()
```

### Seaborn 不同的繪圖
下面的示例顯示了其他一些分布圖示例。 您通過`grid(True)`方法調用激活了一個網格。
```py
import matplotlib.pyplot as plt
import seaborn as sns
titanic=sns.load_dataset('titanic')
age1=titanic['age'].dropna()
fig,axes=plt.subplots(1,2)
sns.distplot(age1,ax=axes[0])
plt.grid(True)
sns.distplot(age1,rug=True,ax=axes[1])
plt.show()
```

[下載示例](https://gum.co/mpdp)
- 介紹
- 學習 python 的 7 個理由
- 為什么 Python 很棒
- 學習 Python
- 入門
- 執行 Python 腳本
- 變量
- 字符串
- 字符串替換
- 字符串連接
- 字符串查找
- 分割
- 隨機數
- 鍵盤輸入
- 控制結構
- if語句
- for循環
- while循環
- 數據與操作
- 函數
- 列表
- 列表操作
- 排序列表
- range函數
- 字典
- 讀取文件
- 寫入文件
- 嵌套循環
- 切片
- 多個返回值
- 作用域
- 時間和日期
- try except
- 如何使用pip和 pypi
- 面向對象
- 類
- 構造函數
- 獲取器和設置器
- 模塊
- 繼承
- 靜態方法
- 可迭代對象
- Python 類方法
- 多重繼承
- 高級
- 虛擬環境
- 枚舉
- Pickle
- 正則表達式
- JSON 和 python
- python 讀取 json 文件
- 裝飾器
- 網絡服務器
- 音頻
- 用 Python 播放聲音
- python 文字轉語音
- 將 MP3 轉換為 WAV
- 轉錄音頻
- Tkinter
- Tkinter
- Tkinter 按鈕
- Tkinter 菜單
- Tkinter 標簽
- Tkinter 圖片
- Tkinter 畫布
- Tkinter 復選框
- Tkinter 輸入框
- Tkinter 文件對話框
- Tkinter 框架
- Tkinter 列表框
- Tkinter 消息框
- Tkinter 單選按鈕
- Tkinter 刻度
- 繪圖
- Matplotlib 條形圖
- Matplotlib 折線圖
- Seaborn 分布圖
- Seaborn 繪圖
- Seaborn 箱形圖
- Seaborn 熱力圖
- Seaborn 直線圖
- Seaborn 成對圖
- Seaborn 調色板
- Seaborn Pandas
- Seaborn 散點圖
- Plotly
- PyQt
- PyQt
- 安裝 PyQt
- PyQt Hello World
- PyQt 按鈕
- PyQt QMessageBox
- PyQt 網格
- QLineEdit
- PyQT QPixmap
- PyQt 組合框
- QCheckBox
- QSlider
- 進度條
- PyQt 表格
- QVBoxLayout
- PyQt 樣式
- 編譯 PyQt 到 EXE
- QDial
- QCheckBox
- PyQt 單選按鈕
- PyQt 分組框
- PyQt 工具提示
- PyQt 工具箱
- PyQt 工具欄
- PyQt 菜單欄
- PyQt 標簽小部件
- PyQt 自動補全
- PyQt 列表框
- PyQt 輸入對話框
- Qt Designer Python
- 機器學習
- 數據科學
- 如何從機器學習和 AI 認真地起步
- 為什么要使用 Python 進行機器學習?
- 機器學習庫
- 什么是機器學習?
- 區分機器學習,深度學習和 AI?
- 機器學習
- 機器學習算法比較
- 為什么要使用 Scikit-Learn?
- 如何在 Python 中加載機器學習數據
- 機器學習分類器
- 機器學習回歸
- Python 中的多項式回歸
- 決策樹
- k 最近鄰
- 訓練測試拆分
- 人臉檢測
- 如何為 scikit-learn 機器學習準備數據
- Selenium
- Selenium 瀏覽器
- Selenium Cookie
- Selenium 執行 JavaScript
- Selenium 按 ID 查找元素
- Selenium 無頭 Firefox
- Selenium Firefox
- Selenium 獲取 HTML
- Selenium 鍵盤
- Selenium 最大化
- Selenium 截圖
- Selenium 向下滾動
- Selenium 切換到窗口
- Selenium 等待頁面加載
- Flask 教程
- Flask 教程:Hello World
- Flask 教程:模板
- Flask 教程:路由