【发布时间】:2018-04-05 11:17:59
【问题描述】:
我正在使用 seaborn 创建具有边际分布的 kdeplot,如 this answer 中所述。我稍微修改了代码来给我这个:
import matplotlib.pyplot as plt
import seaborn as sns
iris = sns.load_dataset("iris")
setosa = iris.loc[iris.species == "setosa"]
virginica = iris.loc[iris.species == "virginica"]
g = sns.JointGrid(x="sepal_width", y="petal_length", data=iris)
sns.kdeplot(setosa.sepal_width, setosa.sepal_length, cmap="Reds",
shade=False, shade_lowest=False, ax=g.ax_joint)
sns.kdeplot(virginica.sepal_width, virginica.sepal_length, cmap="Blues",
shade=False, shade_lowest=False, ax=g.ax_joint)
sns.distplot(setosa.sepal_width, kde=True, hist=False, color="r", ax=g.ax_marg_x)
sns.distplot(virginica.sepal_width, kde=True, hist=False, color="b", ax=g.ax_marg_x)
sns.distplot(setosa.sepal_length, kde=True, hist=False, color="r", ax=g.ax_marg_y, vertical=True)
sns.distplot(virginica.sepal_length, kde=True, hist=False, color="b", ax=g.ax_marg_y, vertical=True)
plt.show()
这是不可能以黑白打印的。 如何让 seaborn 以特定样式(点/虚线/...)的方式打印 kdeplot 和 distplot 线,以使它们在黑白打印时可区分?
related questions 处理似乎支持这一点的其他类型的情节,但kdeplot 和distplot 似乎不支持这一点。
【问题讨论】:
-
您得到的答案为您提供了minimal reproducible example。然而,你不使用这个,而是使用一些没人可以运行的代码。
-
@ImportanceOfBeingErnest 好点。对其进行了编辑以包含一个更好的示例。
-
你是如何让两个 kdeplots 出现在同一个图上的?我尝试了非常相似的代码,但一次只显示一个。
标签: python matplotlib seaborn