一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

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

服務器之家 - 腳本之家 - Python - Python中seaborn庫之countplot的數據可視化使用

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

2021-11-29 10:59cymx66688 Python

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

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

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

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

導入seaborn庫

?
1
import seaborn as sns

使用countplot

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

原始數據如下:

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

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

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

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

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

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

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

第二種方法

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

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

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

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

?
1
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不可缺少,必須要有其中一個。

?
1
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的字段排序。排序的方式為列表。

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

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

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

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

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:使用不同的調色板

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

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

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

ax用來指定坐標系。

?
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庫之countplot的數據可視化使用

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

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

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 咪咪爱小说 | 久久亚洲午夜牛牛影视 | 精品久久99麻豆蜜桃666 | 精品国产一区二区三区在线观看 | 息与子中文字幕在线 | 草莓永久地域网名入2022 | 国产欧美精品专区一区二区 | 久久中文电影 | 天堂日韩 | 亚洲AV国产国产久青草 | 国产一区二区三区高清视频 | 给我免费的视频在线观看 | 欧美亚洲国产精品久久久 | 日本hd18| 亚洲品质自拍视频 | 国产肥臀 | 国产欧美精品 | 亚洲精品日韩专区在线观看 | 久9视频这里只有精品123 | 欧美日韩中文字幕久久伊人 | 日韩视频在线观看中字 | 欧美在线视频一区 | 996热精品视频在线观看 | 亚洲国产成人久久精品影视 | 奇米影视7777久久精品 | 青青草原伊人网 | 成年人黄色录像 | 和岳m的小说 | 日本偷偷操 | 99免费看| 垫底辣妹免费观看完整版 | 风间由美一区二区播放合集 | 九九99热久久999精品 | 国产欧美va欧美va香蕉在线观 | 把内裤拔到一边高h1v1 | 国产实拍会所女技师在线 | 色戒真做gif动图 | 催眠白丝舞蹈老师小说 | 九九精品视频在线观看 | 美女牲交毛片一级视频 | 亚洲欧美日韩另类在线一 |