<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Seaborn 繪圖 > 原文: [https://pythonbasics.org/seaborn_barplot/](https://pythonbasics.org/seaborn_barplot/) Seaborn 支持多種類型的條形圖。 我們將 Seaborn 與 Matplotlib 結合起來演示了幾個繪圖。 Seaborn 包含幾個數據集(titanic 和其他),但這只是一個演示。 您可以將任何類型的數據傳遞到繪圖。 ## 條形圖示例 ### 條形圖 用`barplot()`方法創建一個條形圖。 下面的條形圖根據類別顯示了泰坦尼克號撞車事故的幸存者。 您會看到這些條形圖隨著船沉沒而下降:) 調色板參數定義了要使用的顏色,當前使用的是`"hls"`,但可以使用任何調色板。 ```py import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns sns.set_context('paper') # load dataset titanic = sns.load_dataset('titanic') print(titanic.head()) # create plot sns.barplot(x = 'sex', y = 'survived', hue = 'class', data = titanic, palette = 'hls', order = ['male', 'female'], capsize = 0.05, saturation = 8, errcolor = 'gray', errwidth = 2, ci = 'sd' ) print(titanic.groupby(['sex', 'class']).mean()['survived']) print(titanic.groupby(['sex', 'class']).std()['survived']) plt.show() ``` ![barplot](https://img.kancloud.cn/f1/b2/f1b27550db8c3b427e0ccc1e107a1af6_640x480.jpg) ### 水平條形圖 該條形圖可以是使用`barplot()`方法的水平圖。 在下面的示例中,兩個條形圖是重疊的,顯示了百分比作為總崩潰的一部分。 ```py import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns sns.set_context('paper') crashes = sns.load_dataset('car_crashes').sort_values('total', ascending = False) f, ax = plt.subplots(figsize = (6,15)) sns.set_color_codes('pastel') sns.barplot(x = 'total', y = 'abbrev', data = crashes, label = 'Total', color = 'b', edgecolor = 'w') sns.set_color_codes('muted') sns.barplot(x = 'alcohol', y = 'abbrev', data = crashes, label = 'Alcohol-involved', color = 'b', edgecolor = 'w') ax.legend(ncol = 2, loc = 'lower right') sns.despine(left = True, bottom = True) plt.show() ``` ![barplot horizontal](https://img.kancloud.cn/13/47/1347806e74948984f13ca46d4e8cbe18_600x646.jpg) ### 條形圖提示 下面的條形圖提示圖使用提示數據集。 它顯示了根據性別收到的提示數量。 它使用藍調調色板,該調色板具有藍色的變體。 ```py import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns sns.set_context('paper') tips = sns.load_dataset('tips') sns.barplot(x = 'day', y = 'total_bill', hue = 'sex', data = tips, palette = 'Blues', edgecolor = 'w') tips.groupby(['day','sex']).mean() plt.show() ``` ![barplot tips](https://img.kancloud.cn/fa/4b/fa4ba40cd75cc6a6977a57ac3d26c05b_640x480.jpg) ### 計數圖 可以將計數圖視為跨類別變量的直方圖。下面的示例演示了計數圖。 ```py import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns sns.set_context('paper') # load dataset titanic = sns.load_dataset('titanic') print(titanic.head()) # create plot sns.countplot(x = 'class', hue = 'who', data = titanic, palette = 'magma') plt.title('Survivors') plt.show() ``` ![countplot](https://img.kancloud.cn/7c/23/7c239f723829204f7ccec2f89aca889f_640x480.jpg)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看