最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python中seaborn庫之countplot的數(shù)據(jù)可視化使用

 更新時間:2021年06月11日 10:24:09   作者:cymx66688  
在Python數(shù)據(jù)可視化中,seaborn較好的提供了圖形的一些可視化功效。本文詳細的介紹了Python中seaborn庫之countplot的數(shù)據(jù)可視化使用,感興趣的可以了解一下

在Python數(shù)據(jù)可視化中,seaborn較好的提供了圖形的一些可視化功效。

seaborn官方文檔見鏈接:http://seaborn.pydata.org/api.html

countplot是seaborn庫中分類圖的一種,作用是使用條形顯示每個分箱器中的觀察計數(shù)。接下來,對seaborn中的countplot方法進行詳細的一個講解,希望可以幫助到剛入門的同行。

導入seaborn庫

import seaborn as sns

使用countplot

sns.countplot()

countplot方法中必須要x或者y參數(shù),不然就報錯。

官方給出的countplot方法及參數(shù):

sns.countplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, orient=None, color=None, palette=None, saturation=0.75, dodge=True, ax=None, **kwargs)

下面講解countplot方法中的每一個參數(shù)。以泰坦尼克號為例。

原始數(shù)據(jù)如下:

sns.set(style='darkgrid')
titanic = sns.load_dataset('titanic')
titanic.head()

x, y, hue : names of variables in ``data`` or vector data, optional. Inputs for plotting long-form data. See examples for interpretation.

第一種方式

x: x軸上的條形圖,以x標簽劃分統(tǒng)計個數(shù)

y: y軸上的條形圖,以y標簽劃分統(tǒng)計個數(shù)

hue: 在x或y標簽劃分的同時,再以hue標簽劃分統(tǒng)計個數(shù)

sns.countplot(x="class", data=titanic)

sns.countplot(y="class", data=titanic)

sns.countplot(x="class", hue="who", data=titanic)

第二種方法

x: x軸上的條形圖,直接為series數(shù)據(jù)

y: y軸上的條形圖,直接為series數(shù)據(jù)

sns.countplot(x=titanic['class'])

sns.countplot(y=titanic['class'])

data : DataFrame, array, or list of arrays, optional. Dataset for plotting.
If ``x`` and ``y`` are absent, this is interpreted as wide-form. Otherwise it is expected to be long-form.

data: DataFrame或array或array列表,用于繪圖的數(shù)據(jù)集,x或y缺失時,data參數(shù)為數(shù)據(jù)集,同時x或y不可缺少,必須要有其中一個。

sns.countplot(x='class', data=titanic)

order, hue_order : lists of strings, optional.Order to plot the categorical levels in, otherwise the levels are inferred from the data objects.
order, hue_order分別是對x或y的字段排序,hue的字段排序。排序的方式為列表。

sns.countplot(x='class', data=titanic, order=['Third', 'Second', 'First'])

sns.countplot(x='class', hue='who', data=titanic, hue_order=['woman', 'man', 'child'])

orient : "v" | "h", optional
Orientation of the plot (vertical or horizontal). This is usually
inferred from the dtype of the input variables, but can be used to
specify when the "categorical" variable is a numeric or when plotting
wide-form data.
強制定向,v:豎直方向;h:水平方向,具體實例未知。

color : matplotlib color, optional
Color for all of the elements, or seed for a gradient palette.

palette : palette name, list, or dict, optional.Colors to use for the different levels of the ``hue`` variable.
Should be something that can be interpreted by :func:`color_palette`, or a dictionary mapping hue levels to matplotlib colors.

palette:使用不同的調色板

sns.countplot(x="who", data=titanic, palette="Set3")

ax : matplotlib Axes, optional
Axes object to draw the plot onto, otherwise uses the current Axes.

ax用來指定坐標系。

fig, ax = plt.subplots(1, 2, figsize=(10, 5))
sns.countplot(x='class', data=titanic, ax=ax[0])
sns.countplot(y='class', data=titanic, ax=ax[1])

到此這篇關于Python中seaborn庫之countplot的數(shù)據(jù)可視化使用的文章就介紹到這了,更多相關Python seaborn庫countplot內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • 詳解Python裝飾器的四種定義形式

    詳解Python裝飾器的四種定義形式

    裝飾器(decorator)在Python框架中扮演著重要角色,是Python中實現(xiàn)切面編程(AOP)的重要手段,這篇文章主要介紹了Python裝飾器的四種定義形式,需要的朋友可以參考下
    2022-11-11
  • python多版本工具miniconda的配置優(yōu)化實現(xiàn)

    python多版本工具miniconda的配置優(yōu)化實現(xiàn)

    通過Miniconda,您可以輕松地創(chuàng)建和管理多個Python環(huán)境,同時確保每個環(huán)境具有所需的依賴項和軟件包,本文主要介紹了python多版本工具miniconda的配置優(yōu)化實現(xiàn),感興趣的可以了解一下
    2024-01-01
  • Python運算符的使用保姆級教學

    Python運算符的使用保姆級教學

    這篇文章主要給大家介紹了關于Python運算符使用的相關資料,文中總結了Python中的算術運算符、賦值運算符、比較運算符、邏輯運算符、位運算符和成員運算符的用法和特性,需要的朋友可以參考下
    2024-11-11
  • 使用Python實現(xiàn)計算DICOM圖像兩點真實距離

    使用Python實現(xiàn)計算DICOM圖像兩點真實距離

    這篇文章主要為大家詳細介紹了如何使用Python實現(xiàn)計算DICOM圖像兩點真實距離,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下
    2023-11-11
  • 用Python編寫簡單的定時器的方法

    用Python編寫簡單的定時器的方法

    這篇文章主要介紹了用Python編寫簡單的定時器的方法,主要用到了Python中的threading模塊,需要的朋友可以參考下
    2015-05-05
  • 如何用python處理excel表格

    如何用python處理excel表格

    在本篇文章里小編給大家整理了關于python處理excel表格的詳細步驟內容,需要的朋友們可以參考下。
    2020-06-06
  • Python 專題四 文件基礎知識

    Python 專題四 文件基礎知識

    本文主要講述了Python文件基礎知識,包括文件的打開、讀寫、關閉操作、使用循環(huán)讀寫文件及迭代器的知識。具有很好的參考價值。下面跟著小編一起來看下吧
    2017-03-03
  • django框架如何集成celery進行開發(fā)

    django框架如何集成celery進行開發(fā)

    本文給大家詳細講解了在django框架中如何集成celery進行開發(fā),步驟非常詳細,有需要的小伙伴可以參考下
    2017-05-05
  • caffe binaryproto 與 npy相互轉換的實例講解

    caffe binaryproto 與 npy相互轉換的實例講解

    今天小編就為大家分享一篇caffe binaryproto 與 npy相互轉換的實例講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-07-07
  • Pycharm報錯Non-zero?exit?code?(2)的完美解決方案

    Pycharm報錯Non-zero?exit?code?(2)的完美解決方案

    最近在使用pycharm安裝或升級模塊時出現(xiàn)了錯誤,下面這篇文章主要給大家介紹了關于Pycharm報錯Non-zero?exit?code?(2)的完美解決方案,文中通過圖文介紹的非常詳細,需要的朋友可以參考下
    2022-06-06

最新評論

扬中市| 日喀则市| 子长县| 二手房| 鹰潭市| 嘉黎县| 南雄市| 西平县| 彰武县| 岫岩| 柳林县| 体育| 凉山| 容城县| 江安县| 苗栗县| 台东市| 大邑县| 苍溪县| 西藏| 东乡县| 凤山县| 普定县| 民县| 龙山县| 塔河县| 穆棱市| 维西| 嘉善县| 武宁县| 平安县| 大厂| 齐河县| 泸溪县| 磐安县| 汉中市| 上思县| 琼中| 类乌齐县| 闽侯县| 巨鹿县|