python - 更改seaborn分布线的颜色

标签 python matplotlib plot colors seaborn

我想在seaborn包中为xy数据数组指定一行fit的颜色。相反,我所能想到的就是如何更改内核密度函数的颜色和阴影。如何更改高斯拟合的颜色? IE。下面的线应该是红色和蓝色的。在函数中添加阴影(如 "shade":True 参数)也很棒。

import seaborn as sns
sns.distplot(x,kde_kws={"shade":True}, kde=False, fit=stats.gamma, hist=None, color="red", label="label 1");
sns.distplot(y,kde_kws={"shade":True}, kde=False, fit=stats.gamma, hist=None, color="blue", label="label 2");

enter image description here

最佳答案

要更改拟合曲线的颜色,您需要设置fit_kws参数。但 fit_kws 不支持着色。您仍然可以通过几行额外的代码来遮蔽拟合曲线下方的区域,如下所示,但我认为这是您发布的另一个问题的答案。

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

sns.set()
np.random.seed(0)
x = np.random.randn(100)
y = np.random.normal(loc=6.0, scale=1, size=(50,))

ax = sns.distplot(x, fit_kws={"color":"red"}, kde=False,
        fit=stats.gamma, hist=None, label="label 1");
ax = sns.distplot(y, fit_kws={"color":"blue"}, kde=False,
        fit=stats.gamma, hist=None, label="label 2");

plt.show(block=False)

代码运行结果如下: enter image description here

关于python - 更改seaborn分布线的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47644966/

相关文章:

python - 在使用 read_fwf() 读取的 Pandas 数据框中查找虚假数据

python - 新的曼巴环境强制 torch CPU,我不知道为什么

python - 运行时错误 : Can not put single artist in more than one figure when using matplotlib 1. 5

python - matplotlib 上的多个网格

matlab - 如何在 MATLAB 中预测和扩展作为一维向量获取的数据?

python - matplotlib 等高线图 : warning about `no contour levels were found`

matlab - Matlab 图中的相对标记大小

python - 如何使用距离矩阵和 kmedoids 将新观测值分配给聚类?

python - 如何解决 python 代码运行缓慢的问题

python - FigureCanvasTkAgg 的声明导致内存泄漏