如何在seaborn pairplot上绘制身份线? [英] How can I plot identity lines on a seaborn pairplot?

查看:57
本文介绍了如何在seaborn pairplot上绘制身份线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Seaborn 的配对图:

I'm using Seaborn's pairplot:

g = sns.pairplot(df)

是否可以在每个散点图上绘制标识线?

Is it possible to draw identity lines on each of the scatter plots?

推荐答案

定义一个函数,该函数将在当前轴上绘制标识线,并使用 PairGrid.map_offdiag 将其应用于网格的非对角线轴() 方法.

Define a function which will plot the identity line on the current axes, and apply it to the off-diagonal axes of the grid using PairGrid.map_offdiag() method.

例如:

import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt

def plot_unity(xdata, ydata, **kwargs):
    mn = min(xdata.min(), ydata.min())
    mx = max(xdata.max(), ydata.max())
    points = np.linspace(mn, mx, 100)
    plt.gca().plot(points, points, color='k', marker=None,
            linestyle='--', linewidth=1.0)

ds = sns.load_dataset('iris')
grid = sns.pairplot(ds)
grid.map_offdiag(plot_unity)

这会在我的设置中生成以下图.您可以调整 plot_unity 函数的 kwargs 以根据需要设置绘图样式.

This makes the following plot on my setup. You can tweak the kwargs of the plot_unity function to style the plot however you want.

这篇关于如何在seaborn pairplot上绘制身份线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆