我正在制作一个大的PairGrid
图形,但无法将图例设置在绘图区域之外(右侧)。PairGrid
似乎没有继承FaceGrid
的legend_out
选项。这是我的尝试,你可以看到图例与图形重叠。
from random import choice
from numpy import random
from matplotlib import pyplot as plt
import seaborn as sns
import pandas as pd
def my_kdeplot(dfx, dfy, *args, **kwargs):
ax = sns.kdeplot(dfx, dfy, alpha=0.7,
cmap=sns.light_palette(kwargs['color'], as_cmap=True))
names = [choice('ABCDE') for _ in range(1000)]
df = pd.DataFrame(list(zip(names, *[random.random(1000) for _ in range(5)])),
columns=['names','A','B','C','D','E'])
g = sns.PairGrid(df, hue='names')
g.map_lower(my_kdeplot)
g.map_upper(plt.scatter, alpha=0.7)
g.map_diag(plt.hist)
g = g.add_legend(fontsize=14)
sns.plt.savefig('fig.png')