- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用泰坦尼克号数据集,并尝试针对分类变量生成一对数值变量图。我可以用 Seaborn 的 catplot
绘制一个数字变量对一个分类变量的图:
import seaborn as sns
sns.catplot(data=train, x='Fare', y='Sex')
x_vars = ['Fare']
y_vars = ['Sex']
g = sns.PairGrid(train, x_vars=x_vars, y_vars=y_vars)
g.map(sns.catplot)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-75-c284a7cfd727> in <module>
9 #g.map_diag(lambda x, **kwargs: sns.catplot(x, x, **kwargs), jitter=True, kind="bar")
10 #g.map(sns.scatterplot, y_jitter=1)#, hue=train["Survived"])
---> 11 g.map(sns.catplot)#, hue=train["Survived"])
~/MLProject/book1/lib/python3.8/site-packages/seaborn/axisgrid.py in map(self, func, **kwargs)
1363 row_indices, col_indices = np.indices(self.axes.shape)
1364 indices = zip(row_indices.flat, col_indices.flat)
-> 1365 self._map_bivariate(func, indices, **kwargs)
1366 return self
1367
~/MLProject/book1/lib/python3.8/site-packages/seaborn/axisgrid.py in _map_bivariate(self, func, indices, **kwargs)
1504 y_var = self.y_vars[i]
1505 ax = self.axes[i, j]
-> 1506 self._plot_bivariate(x_var, y_var, ax, func, kw_color, **kws)
1507 self._add_axis_labels()
1508
~/MLProject/book1/lib/python3.8/site-packages/seaborn/axisgrid.py in _plot_bivariate(self, x_var, y_var, ax, func, kw_color, **kwargs)
1534 color = self.palette[k] if kw_color is None else kw_color
1535
-> 1536 func(x, y, label=label_k, color=color, **kwargs)
1537
1538 self._clean_axis(ax)
~/MLProject/book1/lib/python3.8/site-packages/seaborn/categorical.py in catplot(x, y, hue, data, row, col, col_wrap, estimator, ci, n_boot, units, seed, order, hue_order, row_order, col_order, kind, height, aspect, orient, color, palette, legend, legend_out, sharex, sharey, margin_titles, facet_kws, **kwargs)
3760
3761 # Initialize the facets
-> 3762 g = FacetGrid(**facet_kws)
3763
3764 # Draw the plot onto the facets
~/MLProject/book1/lib/python3.8/site-packages/seaborn/axisgrid.py in __init__(self, data, row, col, hue, col_wrap, sharex, sharey, height, aspect, palette, row_order, col_order, hue_order, hue_kws, dropna, legend_out, despine, margin_titles, xlim, ylim, subplot_kws, gridspec_kws, size)
268 # Make a boolean mask that is True anywhere there is an NA
269 # value in one of the faceting variables, but only if dropna is True
--> 270 none_na = np.zeros(len(data), np.bool)
271 if dropna:
272 row_na = none_na if row is None else data[row].isnull()
TypeError: object of type 'NoneType' has no len()
g.map(sns.catplot)
与
g.map(sns.scatterplot)
它没有错误地成功绘制图形。
catplot
与
PairGrid
?
最佳答案
@ImportanceOfBeingErnest 已经在上面的评论中给出了正确答案:将 sns.catplot()
结合起来是没有意义的。用单独创建的 FacetGrid
, 因为 sns.catplot()
创建自己的 FacetGrid
被调用时。
无论如何,sns.catplot()
调用另一个 seaborn 函数在网格的每个单元格中进行实际绘图。可以通过指定 kind
来选择该功能。 sns.catplot()
的关键字参数.默认为 kind="strip"
.
所以如果你想手动创建一个 FacetGrid
然后映射 sns.catplot()
到它,但没有指定 kind
,你也可以用sns.stripplot()
反而。这确实有效,但泰坦尼克号数据集太大,无法提供非常有用的信息,所以我会改用 fiddle 图:
import seaborn as sns
sns.set()
titanic = sns.load_dataset('titanic')
num_vars = ['age', 'fare']
cat_vars = ['pclass', 'embarked', 'sex']
g = sns.PairGrid(data=titanic, x_vars=cat_vars, y_vars=num_vars)
g.map(sns.violinplot)
g.map()
两次。更改要传递给
g.map()
的绘图函数的默认参数,您可以使用
*
定义这些函数的修改版本和
**
运营商:
import seaborn as sns
sns.set()
titanic = sns.load_dataset('titanic')
num_vars = ['age', 'fare']
cat_vars = ['pclass', 'embarked', 'sex']
def violin_empty(*args, **kwargs):
kwargs['color'] = 'lightblue'
return sns.violinplot(*args, **kwargs, inner=None)
def swarm_small(*args, **kwargs):
kwargs['color'] = 'black'
return sns.swarmplot(*args, **kwargs, size=1)
g = sns.PairGrid(data=titanic, x_vars=cat_vars, y_vars=num_vars)
g.map(violin_empty)
g.map(swarm_small)
关于python - Seaborn 猫图结合 PairGrid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59922430/
我正在使用泰坦尼克号数据集,并尝试针对分类变量生成一对数值变量图。我可以用 Seaborn 的 catplot绘制一个数字变量对一个分类变量的图: import seaborn as sns sns.
我有一个像这样的数据集(有点): f1 f2 f3 value 4 2 3 0.927252 1 3 0 0.153415 0 1 1
我有 7 个特征,我想绘制 2 个特征的所有组合。我想将这些数据可视化,如下所示。我可以通过在 matpltlib 中的子图之后添加子图来手动完成,但是有这个功能吗?这类情节有专门的名字吗? 谢谢 答
我有一个数据框,其中包含来自几个不同模型的土壤温度数据,我想为其创建一个散点图矩阵。数据框如下所示: dataframe structure 数据是按模型(或站)组织的,我还包括了几个列来区分冷季或暖
我正在使用 seaborn 进行绘图我正在使用 seaborn.PairGrid功能。这是创建 6 x 6 网格,其中对角线图是直方图,非对角线图是散点图。现在我想为每行图设置不同的 y 范围,并为每
我尝试过使用answer至 Hide Axis Titles in Seaborn ,它适用于 heatmap,但最终会得到两个图:第一个是没有轴标题的空网格,第二个是 PairGrid 但仍带有轴标
我对 seaborn Pairgrid 有点吃力。 假设我有一个这样的 Pairgrid: 如您所见,上三角图反射(reflect)了下三角图。我希望能够只绘制下三角图,但到目前为止我发现没有简单的方
是否有可以与 g.map_lower 或 g.map_upper 一起使用的 matplotlib 或 seaborn 图来获取为每个双变量图显示的相关系数,如下所示?手动映射 plt.text 以获
在下面的示例中,我如何使用 seaborn.PairGrid() 重现由 seaborn.pairplot() 创建的绘图?具体来说,我希望对角线分布跨越垂直轴。带有白色边框等的标记……也很棒。谢谢!
在 Jupyter Notebook 中,我正在使用 seaborn 结合 ipywidgets 可视化 Iris 数据集。这很好用,只是速度不是那么快,因为每次选择“versicolor”、“vir
我希望重现 that tutorial 中的 PairGrid 图,但在本地,我的条形图没有像教程中那样堆叠,我不知道如何让它们堆叠起来。 import seaborn as sns import m
我试图绘制一个 PairGrid 在对角线上使用密度估计,在上三角部分和下三角中的成对线性回归模型部分。这是我的数据文件: df.head() 这是我的代码: g = sns.PairGrid(df,
我正在做一个大 PairGrid图,我无法在图外设置图例(右侧)。 PairGrid似乎没有继承 legend_out FaceGrid 的选项.到目前为止,这是我的尝试,您可以看到图例与图重叠。 f
我正在尝试绘制与 seaborn 文档中描述的情况非常相似的情况 http://seaborn.pydata.org/tutorial/axis_grids.html#plotting-pairwis
取自documentation : >>> import matplotlib.pyplot as plt >>> import seaborn as sns; sns.set() >>> iris
我真的很喜欢 Seaborn 的 PairGrid 的功能.但是,我无法将子图 reshape 到令我满意的程度。例如,下面的代码将返回一个包含 1 列和 2 行的图形,反射(reflect) 1 个
我正在尝试在 Seaborn 网格中获取 hexbin 图。我有以下代码, # Works in Jupyter with Python 2 Kernel. %matplotlib inline im
在花了一些时间了解 PairGrid 功能的工作原理之后,我已经快成功了。下面是生成我想要的绘图的代码,但 histfunc 中缺少一个小细节。我想要的是对角线上绘制的直方图的标题。如何将数据框列名称
有没有一种方法可以轻松地为 Seaborn 对图中的每个子图添加轴标签?这与此有关 question但我不想添加刻度标签,而是想添加轴标签,因为我拥有的配对图是 9*9,我不想每次都向下滚动以检查列名
这是我努力绘制的 pairgrid 图,该图使用下部的 kdeplot 和 2 种色调: 我的脚本是: import seaborn as sns g = sns.PairGrid(df2,hue='
我是一名优秀的程序员,十分优秀!