【发布时间】:2022-01-18 01:17:25
【问题描述】:
我已经尝试了几个小时了。
我本质上是想让颜色条的比例相同。
我从上一篇文章中选择了这个例子,其中一个建议是使用kwargs = {'levels': np.arange(0, 0.15, 0.01)} 行。我已经包含了它,但我没有看到任何变化,比例保持不变。
这是我正在使用的代码:
import numpy as np
import seaborn as sns
import pandas
import matplotlib.pyplot as plt
from matplotlib import rcParams
np.random.seed(10)
sns.set(color_codes=True)
rcParams['font.family'] = 'sans-serif'
rcParams['font.sans-serif'] = ['Arial']
plt.ioff()
kwargs = {'levels': np.arange(0, 0.15, 0.01)} #trying to get the colorbar scales to be the same
f, ax = plt.subplots(figsize=(7, 5))
ax.tick_params(axis='both', which='major', labelsize=22)
mean, cov = [0, 2], [(2, 1), (.5, 1)]
x1, y1 = np.random.multivariate_normal(mean, cov, size=50).T
mean, cov = [5, 7], [(3, 2), (7, 1)]
x2, y2 = np.random.multivariate_normal(mean, cov, size=50).T
sns.kdeplot(x1, y1, cmap="Reds", shade=True, shade_lowest=False,
alpha=0.66, legend=False, cbar=True, **kwargs, ax= ax )
sns.kdeplot(x2, y2, cmap="Greens", shade=True, shade_lowest=False, alpha=0.66,\
legend=False, cbar=True,**kwargs, ax = ax)
plt.xlabel("foo", fontsize=22)
plt.ylabel("bar", fontsize=22)
【问题讨论】:
-
我觉得魔法发生在这部分代码中:github.com/mwaskom/seaborn/blob/… 据我了解,0 到 1 之间的级别被视为分位数并映射回来,这会导致颜色条不一致。我不确定是否以及如何规避这种情况。
-
将它们放入长格式数据框中并使用
hue。
标签: python matplotlib seaborn