首页 > 解决方案 > 我在哪里可以找到关于 seaborn 中的联合绘图函数或 Python 中的 matplotlib 中的此参数“joint_kws”的详细定义?

问题描述

以下是该功能的说明:</p>

def jointplot(x, y, data=None, kind="scatter", stat_func=stats.pearsonr,
          color=None, size=6, ratio=5, space=.2,
          dropna=True, xlim=None, ylim=None,
          joint_kws=None, marginal_kws=None, annot_kws=None, **kwargs)

以下是最后几个可选参数的说明:

{joint, marginal, annot}_kws : dicts, optional
    Additional keyword arguments for the plot components.
kwargs : key, value pairings
    Additional keyword arguments are passed to the function used to
    draw the plot on the joint Axes, superseding items in the
    ``joint_kws`` dictionary.

文档中提到我可以传入一个像'joint_kws'或'marginal_kws'这样的字典来控制情节,但是你在哪里可以找到这些字典的定义和用法呢?我在官方文档中没有看到。谁能帮我?谢谢!

标签: pythonmatplotlibjupyter-notebookseaborn

解决方案


正如文档所说,这些字典被传递给用于在关节轴或边缘轴上绘制的绘图函数。因此,要传递的实际密钥取决于您所做的情节类型。

例如,如果您正在这样做,jointplot(..., kind="kde", ...)那么 seaborn 将用于sns.kdeplot()在关节轴上进行绘图,因此可以传递给该函数的任何参数都可以在joint_kws=. 查看的定义sns.kdeplot(),我发现我可以传递一个参数shade=(“如果为真,则在 KDE 曲线下的区域中着色(或者当数据是双变量时使用填充轮廓绘制)。”),因此,我可以将该参数传递给joint_kws字典:

iris = sns.load_dataset("iris")
g = sns.jointplot("sepal_width", "petal_length", data=iris,kind="kde",
                  space=0, color="g", joint_kws=dict(shade=False))

如果我要跑步,sns.jointplot(..., kind='scatter',...)那么 seaborn 会用它plt.scatter()来绘制实际的情节。我可以查看定义pyplot.scatter()并查看可以在字典中使用哪些键:

tips = sns.load_dataset("tips")
g = sns.jointplot(x="total_bill", y="tip", data=tips, kind='scatter', joint_kws=dict(marker='D', s=50))

推荐阅读