濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > Python中seaborn庫(kù)之countplot的數(shù)據(jù)可視化使用

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

熱門標(biāo)簽:海外網(wǎng)吧地圖標(biāo)注注冊(cè) 南陽(yáng)打電話機(jī)器人 ai電銷機(jī)器人的優(yōu)勢(shì) 地圖標(biāo)注自己和別人標(biāo)注區(qū)別 騰訊地圖標(biāo)注沒(méi)法顯示 打電話機(jī)器人營(yíng)銷 商家地圖標(biāo)注海報(bào) 孝感營(yíng)銷電話機(jī)器人效果怎么樣 聊城語(yǔ)音外呼系統(tǒng)

在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ù)

import seaborn as sns

使用countplot

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ù)如下:

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標(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ù)

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

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分別是對(duì)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.
強(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)色板

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用來(lái)指定坐標(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])

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

您可能感興趣的文章:
  • 利用Python進(jìn)行數(shù)據(jù)可視化的實(shí)例代碼
  • python數(shù)據(jù)可視化之matplotlib.pyplot基礎(chǔ)以及折線圖
  • 淺談哪個(gè)Python庫(kù)才最適合做數(shù)據(jù)可視化
  • python數(shù)據(jù)可視化plt庫(kù)實(shí)例詳解
  • 學(xué)會(huì)Python數(shù)據(jù)可視化必須嘗試這7個(gè)庫(kù)
  • python實(shí)現(xiàn)股票歷史數(shù)據(jù)可視化分析案例
  • Python數(shù)據(jù)可視化之基于pyecharts實(shí)現(xiàn)的地理圖表的繪制
  • Python爬蟲(chóng)實(shí)戰(zhàn)之爬取京東商品數(shù)據(jù)并實(shí)實(shí)現(xiàn)數(shù)據(jù)可視化
  • Python數(shù)據(jù)可視化之用Matplotlib繪制常用圖形
  • Python數(shù)據(jù)可視化之繪制柱狀圖和條形圖
  • python用pyecharts實(shí)現(xiàn)地圖數(shù)據(jù)可視化
  • python數(shù)據(jù)可視化 – 利用Bokeh和Bottle.py在網(wǎng)頁(yè)上展示你的數(shù)據(jù)

標(biāo)簽:楊凌 揚(yáng)州 牡丹江 六盤水 撫州 南寧 聊城 迪慶

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Python中seaborn庫(kù)之countplot的數(shù)據(jù)可視化使用》,本文關(guān)鍵詞  Python,中,seaborn,庫(kù)之,countplot,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Python中seaborn庫(kù)之countplot的數(shù)據(jù)可視化使用》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于Python中seaborn庫(kù)之countplot的數(shù)據(jù)可視化使用的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    重庆市| 政和县| 淮安市| 容城县| 天全县| 抚顺市| 榆树市| 陇川县| 班戈县| 南昌市| 罗源县| 永顺县| 鄄城县| 隆回县| 周口市| 阳江市| 博湖县| 巴中市| 大宁县| 广宗县| 涟源市| 武平县| 新疆| 深泽县| 甘谷县| 隆德县| 永嘉县| 谢通门县| 海口市| 兴山县| 镇安县| 延长县| 安西县| 阿拉尔市| 荥阳市| 金溪县| 抚州市| 大城县| 扶沟县| 延川县| 乌拉特中旗|