Dum*_* ML 1 python pandas seaborn facet-grid
这应该很容易,但我已经尝试了很多东西(基于seaborn relplot:如何控制图例的位置并添加标题,如何向Seaborn Facet Plot添加标题以及文档),但没有任何效果。
我尝试过的事情:
g = sns.relplot(x="col1", y="col2", data=df, height=6, aspect=2);
g.add_legend(title="Col1 x Col2");
Run Code Online (Sandbox Code Playgroud)
还:
g = sns.relplot(x="col1", y="col2", data=df, height=6, aspect=2).set_title('Col1 x Col2')
Run Code Online (Sandbox Code Playgroud)
和:
plt.title('Col1 x Col2')
g = sns.relplot(x="col1", y="col2", data=df, height=6, aspect=2);
Run Code Online (Sandbox Code Playgroud)
好吧,没有任何效果。我希望标题位于图表的顶部,就像 plt.title() 通常所做的那样。
由于您未能包含源 DataFrame,我使用了另一个:
df = sns.load_dataset("tips")
Run Code Online (Sandbox Code Playgroud)
然后我按以下方式创建了relplot :
g = sns.relplot(x="total_bill", y="tip", hue="day", data=df)
g.fig.suptitle('Col1 x Col2', fontsize=16)
g.fig.subplots_adjust(top=0.9);
Run Code Online (Sandbox Code Playgroud)
我得到的结果是:
当然,图像的内容是不同的,但至少你这里有一个标题,图像向下调整,在标题下方留出一些空间。
归档时间: |
|
查看次数: |
3668 次 |
最近记录: |