亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

Python中seaborn庫之countplot的數據可視化使用

瀏覽:6日期:2022-06-17 08:46:31

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

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

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

導入seaborn庫

import seaborn as sns

使用countplot

sns.countplot()

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

官方給出的countplot方法及參數:

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方法中的每一個參數。以泰坦尼克號為例。

原始數據如下:

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

Python中seaborn庫之countplot的數據可視化使用

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標簽劃分統計個數

y: y軸上的條形圖,以y標簽劃分統計個數

hue: 在x或y標簽劃分的同時,再以hue標簽劃分統計個數

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

Python中seaborn庫之countplot的數據可視化使用

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

Python中seaborn庫之countplot的數據可視化使用

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

Python中seaborn庫之countplot的數據可視化使用

第二種方法

x: x軸上的條形圖,直接為series數據

y: y軸上的條形圖,直接為series數據

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

Python中seaborn庫之countplot的數據可視化使用

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

Python中seaborn庫之countplot的數據可視化使用

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列表,用于繪圖的數據集,x或y缺失時,data參數為數據集,同時x或y不可缺少,必須要有其中一個。

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

Python中seaborn庫之countplot的數據可視化使用

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’])

Python中seaborn庫之countplot的數據可視化使用

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

Python中seaborn庫之countplot的數據可視化使用

orient : 'v' | 'h', optionalOrientation of the plot (vertical or horizontal). This is usuallyinferred from the dtype of the input variables, but can be used tospecify when the 'categorical' variable is a numeric or when plottingwide-form data. 強制定向,v:豎直方向;h:水平方向,具體實例未知。

color : matplotlib color, optionalColor 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')

Python中seaborn庫之countplot的數據可視化使用

ax : matplotlib Axes, optionalAxes 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的數據可視化使用

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

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 亚洲国产成人久久一区久久 | 欧美日韩大尺码免费专区 | 国产成人亚洲精品91专区手机 | 视色4se影院在线播放 | 国模沟沟一区二区三区 | 日韩人成免费网站大片 | 美女一级牲交毛片视频 | 中日韩欧美视频 | 日韩精品另类天天更新影院 | 欧美成人性色大片在线观看 | 国产婷婷综合在线精品尤物 | 亚洲欧美一区在线 | 久久久精品久久 | 99re在线精品视频免费 | 国产亚洲一区二区三区在线 | 日本免费看片在线播放 | 亚洲tv成人天堂在线播放 | 在线观看网站国产 | 国产激情一区二区三区成人91 | 天天久久综合 | 久久亚洲成人 | 日韩免费高清一级毛片在线 | 国产黄色三级三级三级 | 国产免费高清福利拍拍拍 | 国产一区国产二区国产三区 | 欧美激情片网站 | 亚洲一区二区三区精品国产 | 亚洲精品乱码久久久久久 | 亚洲一逼 | 国产一区二区三区亚洲综合 | 亚洲精品亚洲九十七页 | 黄色片在线播放 | 日本欧美不卡一区二区三区在线 | 二区三区在线观看 | 91免费精品国偷自产在线在线 | 美女国产网站 | 亚洲不卡免费视频 | 国产羞羞事1000部在线观看 | 草草线在成人免费视频 | 可以直接看的av网址站 | 美国免费高清一级毛片 |