- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试创建一个 seaborn FacetGrid 来显示我拥有的某些数据中集群之间的转换概率。数据有一堆主题和 4 个集群(因此每个主题有 16 个数据点,每对新旧集群一个)。因为这些是概率,所以所有具有相同旧聚类(对于每个主题)的值总和为 1。我想使用 FacetGrid 点图(或堆叠条形图,但对于 seaborn 似乎不可能)显示这些数据,例如每个旧集群是一个单独的列,新集群是一个单独的色调,每个方面都显示主题与概率。
这是生成具有与我的功能相同的玩具 DataFrame 的代码,以及我想要制作的 facetgrid 的代码。然而,当我做这一切时,传说是空的。
df,index = [],0
for subj in [1,2]:
for i,j in itertools.product(range(4),range(4)):
df.append(pd.DataFrame(index=[index],data=dict(subject=subj,old=i,new=j,prob=[.23,.24,.26,.27][j])))
index+=1
df = pd.concat(df)
g = sns.FacetGrid(df,col='old',hue='new',margin_titles=False,legend_out=True)
g.map(sns.pointplot,'subject','prob',join=False)
g.add_legend()
g._legend_data
表明它是空的,并且每个轴
get_legend_handles_labels()
函数都不返回任何内容。这是怎么回事?
g.map(sns.pointplot,'subject','prob',join=False,dodge=.1)
看起来与上面完全相同,对于各种不同的闪避值...
sns.factorplot
而不是 FacetGrid,图例和闪避都有效。我唯一不能使用 sns.factorplot 做的事情是旋转 xtick 标签,但这无论如何都不适用于 Facet Grid 中的
col_wrap
......为什么 FacetGrid 有这个问题?
最佳答案
正如您所注意到的,factorplot
提供了一个更简单的界面来一起使用 pointplot
和 FacetGrid
。图例和闪避不能按照您原来的方式工作的原因是在 hue
中设置 FacetGrid
和在 pointplot
中设置它是不同的。当你在没有pointplot
变量的情况下调用hue
时,它不知道如何闪避,它认为它不需要添加任何图例数据。
选项一是移动使用 hue
变量的位置:
g = sns.FacetGrid(df,col='old', col_wrap=2)
g.map(sns.pointplot, 'subject', 'prob', 'new', dodge=.1, join=False)
g.add_legend()
FacetGrid
而不是仅使用
factorplot
:
g = sns.factorplot(x="subject", y="prob", hue="new", data=df,
col="old", col_wrap=2, size=3,
dodge=.1, join=False)
factorplot
返回一个
FacetGrid
实例,因此原则上应该很容易使用进一步的
FacetGrid
方法来调整绘图。我怀疑您遇到的问题是
this bug ,它将在下一个版本中修复。同时,您可以像这样解决它:
g = sns.factorplot(x="subject", y="prob", hue="new", data=df,
col="old", col_wrap=2, size=3,
dodge=.1, join=False)
for ax in g.axes:
plt.setp(ax.get_xticklabels(), rotation=45)
关于matplotlib - FacetGrid 图例为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28992174/
我正在尝试创建一个 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
我是一名优秀的程序员,十分优秀!