日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

seaborn 子图_Seaborn FacetGrid:进一步完善子图

發(fā)布時間:2023/11/29 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 seaborn 子图_Seaborn FacetGrid:进一步完善子图 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

seaborn 子圖

Data visualizations are essential in data analysis. The famous saying “one picture is worth a thousand words” holds true in the scope of data visualizations as well. In this post, I will explain a well-structured, very informative collection of subplots: FacetGrid.

數(shù)據(jù)可視化在數(shù)據(jù)分析中至關(guān)重要。 著名的諺語“一張圖片值得一千個單詞”在數(shù)據(jù)可視化的范圍內(nèi)也是如此。 在這篇文章中,我將解釋一個結(jié)構(gòu)良好,內(nèi)容豐富的子圖集合: FacetGrid

FacetGrid is basically a grid of subplots. Matplotlib supports creating figures with multiple axes and thus allows to have subplots in one figure. What FacetGrid puts on top of matplotlib’s subplot structure:

FacetGrid基本上是子圖的網(wǎng)格。 Matplotlib支持創(chuàng)建具有多個軸的圖形,因此允許在一個圖形中包含子圖。 FacetGrid在matplotlib的子圖結(jié)構(gòu)之上放了什么:

  • Making the process easier and smoother (with less code)

    使過程更輕松,更流暢(使用更少的代碼)
  • Transfering the structure of dataset to subplots

    將數(shù)據(jù)集的結(jié)構(gòu)轉(zhuǎn)移到子圖

The distribution of a variable or relationship among variables can easily be discovered with FacetGrids. They can have up to three dimensions: row, column, and hue. It will be more clear as we go through examples. So, let’s start.

使用FacetGrids可以輕松發(fā)現(xiàn)變量的分布或變量之間的關(guān)系。 它們最多可以具有三個維度: rowcolumnhue 。 通過示例我們將更加清楚。 所以,讓我們開始吧。

As always we start with importing libraries.

與往常一樣,我們從導(dǎo)入庫開始。

Note: FacetGrid requires the data stored in a pandas dataframe where each row represents an observation and columns represent variables. Thus, we also import pandas.

注意 :FacetGrid要求將數(shù)據(jù)存儲在pandas數(shù)據(jù)框中,其中每一行代表一個觀測值,而各列代表變量。 因此,我們也進口大熊貓。

import numpy as np
import pandas as pdimport matplotlib.pyplot as plt
import seaborn as sns
sns.set(style='darkgrid', color_codes=True)%matplotlib inline

We will use the built-in “tips” dataset of seaborn.

我們將使用seaborn的內(nèi)置“提示”數(shù)據(jù)集。

tip = sns.load_dataset("tips")
tip.head()

FacetGrid object is initialized by passing a dataframe and name of variables to create the structure of axes. The variables used to initialize FacetGrid object needs to be categorical or discrete. The grid structure is created according to the number of categories. For instance, “time” column has two unique values.

通過傳遞數(shù)據(jù)框和變量名稱以創(chuàng)建軸的結(jié)構(gòu)來初始化FacetGrid對象。 用于初始化FacetGrid對象的變量必須是分類的離散的 。 根據(jù)類別數(shù)創(chuàng)建網(wǎng)格結(jié)構(gòu)。 例如,“時間”列具有兩個唯一值。

tip['time'].value_counts()
Dinner 176
Lunch 68
Name: time, dtype: int64

Let’s initialize a FacetGrid object by passing “time” variable to col parameter.

讓我們通過將“ time”變量傳遞給col參數(shù)來初始化FacetGrid對象。

g = sns.FacetGrid(tip, col='time')

We’ve just created a very simple grid with two facets (each subplot is a facet). The size of facets are adjusted using height and aspect parameters.

我們剛剛創(chuàng)建了一個非常簡單的帶有兩個小平面的網(wǎng)格(每個子圖都是一個小平面)。 使用高度 寬比參數(shù)調(diào)整構(gòu)面的大小。

  • Height is the height of facets in inches

    高度是刻面的高度,以英寸為單位
  • Aspect is the ratio of width and height (width=aspect*height). Default value of aspect is 1.

    寬高比是寬度與高度的比率(寬=高寬比*高)。 方面的默認(rèn)值為1。

Let’s update the grid with larger facets.

讓我們用更大的方面更新網(wǎng)格。

g = sns.FacetGrid(tip, col='time', height=5)

It is time to plot data on the grid using FacetGrid.map() method. It takes a plotting function and variable(s) to plot as arguments.

現(xiàn)在該使用FacetGrid.map()方法在網(wǎng)格上繪制數(shù)據(jù)了。 它需要一個繪圖函數(shù)和一個或多個變量作為參數(shù)進行繪圖。

g = sns.FacetGrid(tip, col='time', height=5)
g.map(plt.hist, "total_bill")

The grid shows histogram of “total_bill” based on “time”. Depending on the plotting function, we may need to pass multiple variables for map method. For instance, scatter plots require two variables.

網(wǎng)格顯示基于“時間”的“總賬單”直方圖。 根據(jù)繪圖功能,我們可能需要為map方法傳遞多個變量。 例如,散點圖需要兩個變量。

g = sns.FacetGrid(tip, col='time', height=5)
g.map(plt.scatter, "total_bill", "tip")

Let’s add one more dimension to the grid with row parameter.

讓我們通過row參數(shù)向網(wǎng)格添加一個維度。

g = sns.FacetGrid(tip, row='sex', col='time', height=4)
g.map(plt.scatter, "total_bill", "tip")

Both “sex” and “time” columns have two distinct values so a 2x2 FacetGrid is created. As we can see from the plot above, “total_bill” and “tip” variables have a similar trend for males and females.

“性別”和“時間”列都有兩個不同的值,因此創(chuàng)建了2x2 FacetGrid。 從上圖可以看出,男性和女性的“ total_bill”和“ tip”變量趨勢相似。

The hue parameter allows to add one more dimension to the grid with colors.

hue參數(shù)允許使用顏色向網(wǎng)格添加一個維度。

g = sns.FacetGrid(tip, row='sex', col='time', hue='smoker',
height=4)
g.map(plt.scatter, "total_bill", "tip")
g.add_legend()

We now have an overview of the relationship among “total_bill”, “tip”, and “smoker” variables.

現(xiàn)在,我們對“ total_bill”,“ tip”和“ smoker”變量之間的關(guān)系進行了概述。

The “day” column has 4 unique values:

“天”列具有4個唯一值:

tip.day.value_counts()
Sat 87
Sun 76
Thur 62
Fri 19
Name: day, dtype: int64

We can create a FacetGrid that shows the distribution of “total_bill” in different days. It will show if customers spend more on any particular day.

我們可以創(chuàng)建一個FacetGrid來顯示“ total_bill”在不同日期的分布。 它將顯示客戶在特定日期是否花費更多。

g = sns.FacetGrid(tip, row='day',
row_order = tip.day.value_counts().index,
height=1.5, aspect=4)g.map(sns.distplot, "total_bill", hist=False)

It seems like people tend to spend a little more on the weekend. We have used row_order parameter for this plot. As the name suggests, it determines the order of facets. In the previous plots, we used plotting functions from matplotlib.pyplot interface. But, for the last one, we used a plotting function from seaborn package. It is a nice feature of FacetGrid that provides additional flexibility.

人們似乎傾向于在周末花更多的錢。 我們已為此圖使用row_order參數(shù)。 顧名思義,它決定了構(gòu)面的順序。 在先前的繪圖中,我們使用了來自matplotlib.pyplot接口的繪圖函數(shù)。 但是,對于最后一個,我們使用了seaborn包中的繪圖功能。 這是FacetGrid的一項不錯的功能,可提供額外的靈活性。

There are many more features that can be added on FacetGrids in order to enrich both the functionality and appearance of them. If you want to go deeper, I suggest going over seaborn documentation on FacetGrid.

可以在FacetGrids上添加更多功能,以豐富其功能和外觀。 如果你想更深入,我建議去了上seaborn文檔FacetGrid 。

Thank you for reading. Please let me know if you have any feedback.

感謝您的閱讀。 如果您有任何反饋意見,請告訴我。

  • https://seaborn.pydata.org/generated/seaborn.FacetGrid.html

    https://seaborn.pydata.org/Generated/seaborn.FacetGrid.html

  • https://seaborn.pydata.org/tutorial/axis_grids.html#grid-tutorial

    https://seaborn.pydata.org/tutorial/axis_grids.html#grid-tutorial

翻譯自: https://towardsdatascience.com/seaborn-facetgrid-taking-subplots-further-15ee7af54e44

seaborn 子圖

總結(jié)

以上是生活随笔為你收集整理的seaborn 子图_Seaborn FacetGrid:进一步完善子图的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 日韩久草 | 51自拍视频| 深夜小视频在线观看 | 美日韩丰满少妇在线观看 | 亚洲欲色 | 欧美一卡二卡在线观看 | 成年人看的黄色 | av青青| 97视频一区二区 | 亚洲国产福利 | 不卡中文字幕在线 | 米奇狠狠干 | www日韩在线 | 伊人成年综合网 | 国产三级久久 | 国产黄片毛片 | 天天视频黄色 | 欧美一区二区三区大屁股撅起来 | 美女光屁股视频 | 成人免费网站在线 | 日本一区不卡 | 亚洲手机在线观看 | 涩漫天堂| 四虎永久在线精品免费网址 | 久久国产高清 | 92久久精品一区二区 | 久久精国产 | 久久久久久久网站 | 老司机午夜视频 | 国产男女猛烈无遮挡免费观看网站 | 国产精品久久久久久久免费 | 天天拍夜夜操 | 国产a级网站 | 果冻传媒av | 久久精品色欲国产AV一区二区 | 亚洲激情图片 | 天天干天天操av | 中文字幕无码精品亚洲资源网久久 | www国产亚洲精品久久麻豆 | 免费观看一级一片 | 中文字幕在线视频一区二区三区 | 日本久久亚洲 | 中文字幕一区二区三区人妻不卡 | 最新中文字幕在线播放 | av狠狠干| 丝袜调教91porn | 有声小说 成人专区 | 国产一级爽片 | 黄色福利网站 | 国产专区在线播放 | 破处视频在线观看 | 性欧美一区二区 | 三级影片在线免费观看 | 欧美日韩国产一区 | 97干干 | 狠狠做深爱婷婷久久综合一区 | 精品视频一二三 | 欧美视频一区二区在线 | 黄色av网址大全 | 午夜精品久久久久久久四虎美女版 | 美女吞精视频 | 黄页嫩草| 欧美黄色网 | 免费a网址 | 日韩一区高清 | 天天色天天色天天色 | 欧美精品久久久久久 | 无码精品一区二区三区在线 | 中文在线播放 | 一级伦理农村妇女愉情 | 欧美视频一区二区三区四区在线观看 | 中文字幕影片免费在线观看 | 99ri在线| 国产一区欧美日韩 | 26uuu精品一区二区在线观看 | 黄色一级免费网站 | 欧美αv | 日韩免费av片 | 熊出没之冬日乐翻天免费高清观看 | 日韩在线欧美在线 | 免费播放黄色片 | 欧美日韩在线一区二区三区 | 黄色永久视频 | 在线观看欧美精品 | 丰满岳乱妇一区二区三区 | 国产福利免费在线观看 | 啪啪导航| 久久久久99精品国产片 | 热久久av| 91高清免费 | 日韩中文无 | 六月婷婷综合网 | 中文字幕人妻一区二区三区在线视频 | 久久午夜无码鲁丝片 | 成人免费无遮挡无码黄漫视频 | 国产午夜片 | 一区av在线| 在线看a网站 | 亚洲一区二区在线电影 |