国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術(shù)文章
文章詳情頁

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

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

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

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

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

導(dǎo)入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()

Python中seaborn庫之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)計個數(shù)

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

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

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

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

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

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

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

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

第二種方法

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

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

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

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

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

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

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

Python中seaborn庫之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分別是對x或y的字段排序,hue的字段排序。排序的方式為列表。

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

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

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

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

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

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

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

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

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

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ù)可視化使用

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

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 久草热线视频 | 大狠狠大臿蕉香蕉大视频 | 97在线观看成人免费视频 | 国产三级国产精品国产国在线观看 | 亚洲福利视频一区二区三区 | 韩国免费特一级毛片 | 国产不卡a | 九色porny真实丨国产18 | 欧美人成一本免费观看视频 | 国产欧美日韩精品高清二区综合区 | 成人精品综合免费视频 | 久操福利视频 | 一区二区三区影院 | 国产呦在线观看视频 | 国内久久精品 | 日本一本久 | 精品国产成人在线 | 精品综合久久久久久99 | 欧美亚洲国产片在线观看 | 亚洲成人一级 | 色老久久精品偷偷鲁一区 | 国内精品中文字幕 | 日韩欧美a级高清毛片 | 亚洲免费影院 | 玖草视频在线 | 免费视频一区二区三区四区 | 国产精品免费大片一区二区 | 亚洲天堂在线视频观看 | 国产成 人 综合 亚洲绿色 | 日本欧美三级 | 91亚洲精品久久91 | 天天激情站 | 精品久久久久久久久久久久久久久 | 欧美一级在线看 | 久久三级毛片 | 99视频在线观看免费 | 久久中文字幕综合不卡一二区 | 美女黄频免费观看 | 免费欧洲毛片a级视频 | 国产成人亚洲综合91精品555 | xxx国产老太婆视频 xxx欧美老熟 |