- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个个人特征数据框,例如学校成绩、年龄、体重和高度。我想调查这些数据在 seaborn Facetgrid
中的密度分布。
import pandas as pd
import seaborn as sns
import random
import matplotlib.pyplot as plt
# creation of artifical data
random.seed = 10
high = [random.uniform(3.0,6.0) for i in range(50)]
uni = [random.uniform(1.0, 4.0) for i in range(50)]
math = [random.uniform(1.0, 6.0) for i in range(50)]
bio = [random.uniform(1.0, 6.0) for i in range(50)]
history = [random.uniform(1.0, 6.0) for i in range(50)]
age = [random.randint(15,45) for i in range(50)]
height = [random.randint(150,210) for i in range(50)]
weight = [random.randint(50,100) for i in range(50)]
df = pd.DataFrame()
df["value"] = high + uni + math + bio + history + age + height + weight
df["type"] = 100*["final_exam"] + 150*["grade"] + 150*["body"]
df["id"] = 50*["highschool"] + 50*["university"] + 50*["math"] + 50*["bio"] + 50*["history"] + 50*["age"] + 50*["heigt"] + 50*["weight"]
df["group"] = "A"
df = df[["group", "id", "type", "value"]]
df["para"] =df[["type", "id"]].apply(lambda x: "_".join(x), axis=1)
# Plotting function
def plot_poll(df, **kwargs):
def plot_densitiy_distribution(data, **kwargs):
sns.kdeplot(data["value"], shade=True)
grid_ts = sns.FacetGrid(df, sharey=False, legend_out=True, hue="group",col="type", row="id")
grid_ts = grid_ts.map_dataframe(plot_densitiy_distribution)
plt.tight_layout()
plt.show()
# main
plot_poll(df)
一个人的数据框看起来像这样,但总共有 50 个受访者:
+=======+============+============+=======+=======================+
| group | id | type | value | para |
+=======+============+============+=======+=======================+
| A | highschool | final_exam | 2.7 | final_exam_highschool |
+-------+------------+------------+-------+-----------------------+
| A | university | final_exam | 2.0 | final_exam_university |
+-------+------------+------------+-------+-----------------------+
| A | math | grade | 3.3 | grade_math |
+-------+------------+------------+-------+-----------------------+
..............................................................
+-------+------------+------------+-------+-----------------------+
| A | age | body | 27 | body_age |
+-------+------------+------------+-------+-----------------------+
..............................................................
+=======+============+============+=======+=======================+
图形是这样的:
如您所见,有很多空图,我想重新排列只有包含数据的网格的图。在列中应显示具有相同 type
的网格。下面可以看到一个示例(使用 Paint 创建)。此外,所有列的 x 轴均等缩放。如何单独缩放 x 轴(甚至可能是对数)。
rearranged figure (with Paint)
在此先感谢您的支持,基督徒
最佳答案
如果您只是为了演示目的而隐藏图表(但保留整体网格结构):
for (i,j,k), data in fg.facet_data():
if data.empty:
ax = fg.facet_axis(i, j)
ax.set_axis_off()
关于python - 如何避免 seaborn FacetGrid 中的空网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40186545/
我正在尝试创建一个 seaborn FacetGrid 来显示我拥有的某些数据中集群之间的转换概率。数据有一堆主题和 4 个集群(因此每个主题有 16 个数据点,每对新旧集群一个)。因为这些是概率,所
我的结构遵循 pandas DataFrame: n X Y Z 0 1.000000 1.000000 1.014925 1
我一直在与 seaborn.catplot 一起工作为了有一个条形图(下面的数据样本)将 counts 中的值相加一套的列reasons ,由一组公司分隔: sns.catplot(x='Bill_N
我有以下代码可以创建您可以在图片中看到的情节: g = sns.FacetGrid(data, col="Provincia",col_wrap=6,size=2.5) g.map(sns.barpl
我使用 Seaborn 绘制了一个简单的 RelPlot,它返回了一个 Facetgrid 对象。我使用的代码如下: import seaborn as sns palette = sns.color
我有一组数据,我正在尝试使用 seaborn 中的 FacetGrid 绘制这些数据。每个数据点都有一个与之相关的权重,我想在网格的每个方面绘制一个加权直方图。 例如,假设我有以下(随机创建的)数据集
是否可以使用seaborn创建堆叠条形图facetgrid? g = sns.FacetGrid(data, col="city", col_order=cities, col_wrap=3, hei
提前抱歉图像数量过多,但它们有助于演示问题 我构建了一个数据框,其中包含多个基材、多个层的薄膜厚度测量值,作为坐标的函数: | | Sub | Result | Layer | Row | Co
我正在尝试使用seaborn创建一个Facetgrid来显示我的所有列分布以及正态分布线以与正态分布进行比较。 我在pandas中的数据帧看起来像这样: column values 0
我有 2 个数据帧,1 个有训练数据,另一个有标签。训练数据中有 6 个特征/列,标签数据框中有 1 列。我想要我的面网格中有 6 个图 - 所有这些都是散点图。因此,特征 1 与标签、特征 2 与标
给出以下示例: A = [0, 1, 2] B = [3, 4, 5] C = [6, 7, 8, 9] df = pd.DataFrame(data = {'D': np.random.randn(
我正在尝试将颜色条添加到 3 个 seaborn 绘图的网格中。我可以将颜色条添加到 3 个单独的图,或者在第三个图旁边挤压一个颜色条。我想在第三个图之后有一个颜色条,而不改变最后一个图的大小。 我从
给定一些数据: pt = pd.DataFrame({'alrmV':[000,000,000,101,101,111,111], 'he':[e,e,e,e,h
灵感来自 this page 上的示例,我想用 Iris 数据集制作一个 seaborn facetgrid,它有 6 个方面:3 种 x 2 种类型(花瓣或萼片)。在每个方面,我都需要一个长度(或宽
如果我通过 FacetGrid().map() 更改 plt.plot 实例的线宽,我将丢失图例中线型的详细信息。在此图中,线型从图表中正确可见 但是,如果我增加线宽 z 不再正确显示线型 如果你想重
我想每月绘制数据并每年显示一次年份标签。这是数据: timedates = ['2013-01-01', '2013-02-01', '2013-03-01', '2013-04-01', '2013
在 Seaborn 中,您可以使用 FacetGrid 设置要在其上绘制的数据感知网格。然后,您可以使用 map 或 map_dataframe 方法绘制这些网格。 我无法正确指定与 map 或 ma
我有一个具有以下结构的 DataFrame: interval segment variable value 4 02:00:00 Night weekdays
我正在尝试在 Seaborn 中创建一个 FacetGrid 我的代码目前是: g = sns.FacetGrid(df_reduced, col="ActualExternal", margin_t
我想在 Facetgrid 的每个图中反转 y 轴。 下面是代码的简化示例: import pandas as pd import numpy as np import seaborn as sns
我是一名优秀的程序员,十分优秀!