激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

腳本之家,腳本語(yǔ)言編程技術(shù)及教程分享平臺(tái)!
分類導(dǎo)航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務(wù)器之家 - 腳本之家 - Python - Python中seaborn庫(kù)之countplot的數(shù)據(jù)可視化使用

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

2021-11-29 10:59cymx66688 Python

在Python數(shù)據(jù)可視化中,seaborn較好的提供了圖形的一些可視化功效。本文詳細(xì)的介紹了Python中seaborn庫(kù)之countplot的數(shù)據(jù)可視化使用,感興趣的可以了解一下

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

seaborn官方文檔見(jiàn)鏈接:http://seaborn.pydata.org/api.html

countplot是seaborn庫(kù)中分類圖的一種,作用是使用條形顯示每個(gè)分箱器中的觀察計(jì)數(shù)。接下來(lái),對(duì)seaborn中的countplot方法進(jìn)行詳細(xì)的一個(gè)講解,希望可以幫助到剛?cè)腴T的同行。

導(dǎo)入seaborn庫(kù)

?
1
import seaborn as sns

使用countplot

?
1
sns.countplot()

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

官方給出的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方法中的每一個(gè)參數(shù)。以泰坦尼克號(hào)為例。

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

?
1
2
3
sns.set(style='darkgrid')
titanic = sns.load_dataset('titanic')
titanic.head()

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

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標(biāo)簽劃分統(tǒng)計(jì)個(gè)數(shù)

y: y軸上的條形圖,以y標(biāo)簽劃分統(tǒng)計(jì)個(gè)數(shù)

hue: 在x或y標(biāo)簽劃分的同時(shí),再以hue標(biāo)簽劃分統(tǒng)計(jì)個(gè)數(shù)

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

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

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

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

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

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

第二種方法

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

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

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

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

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

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

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缺失時(shí),data參數(shù)為數(shù)據(jù)集,同時(shí)x或y不可缺少,必須要有其中一個(gè)。

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

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

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分別是對(duì)x或y的字段排序,hue的字段排序。排序的方式為列表。

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

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

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

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

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.
強(qiáng)制定向,v:豎直方向;h:水平方向,具體實(shí)例未知。

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:使用不同的調(diào)色板

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

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

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

ax用來(lái)指定坐標(biāo)系。

?
1
2
3
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庫(kù)之countplot的數(shù)據(jù)可視化使用

到此這篇關(guān)于Python中seaborn庫(kù)之countplot的數(shù)據(jù)可視化使用的文章就介紹到這了,更多相關(guān)Python seaborn庫(kù)countplot內(nèi)容請(qǐng)搜索服務(wù)器之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持服務(wù)器之家!

原文鏈接:https://www.cnblogs.com/cymx66688/p/10536403.html

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产女做a爱免费视频 | 免费看毛片网站 | 曰批全过程40分钟免费视频多人 | 免费黄色一级网站 | 91av在线影院 | 在线成人免费视频 | 羞羞视频免费观看入口 | 调教小男生抽打尿孔嗯啊视频 | 99re热视频这里只精品 | 午夜国产在线 | 黄色一级毛片免费看 | 最新中文字幕第一页视频 | 亚洲91精品 | av在线1 | 久久久精品精品 | 国产精品hd免费观看 | 久久艹逼 | 国产一区二区三区四区精 | 久久久日韩精品一区二区三区 | 午夜精品久久久久久久99热浪潮 | 亚洲免费在线看 | 国产一区二区不卡 | 牛牛a级毛片在线播放 | 97视频 | 成人不卡一区二区 | 国产草草视频 | 香蕉秀 | 欧美一区二区网站 | av在线免费播放 | 亚洲欧美在线视频免费 | 午夜在线成人 | 国产在线观看91精品 | 91久久线看在观草草青青 | 日本免费一区二区三区四区 | 成人久久久久久久久 | 美女羞羞视频在线观看 | 欧美日韩免费在线观看视频 | 欧美一级黄色免费 | chinese xvideos gay | 国产精选久久久 | 欧美成人性色 |