1

This should be easy, but I've tried many things (based on seaborn relplot: how to control the location of the legend and add title, How to add a title to Seaborn Facet Plot and also the documentation), but nothing worked.

Things I've tried:

g = sns.relplot(x="col1", y="col2", data=df, height=6, aspect=2);
g.add_legend(title="Col1 x Col2");

Also:

g = sns.relplot(x="col1", y="col2", data=df, height=6, aspect=2).set_title('Col1 x Col2')

And:

plt.title('Col1 x Col2')
g = sns.relplot(x="col1", y="col2", data=df, height=6, aspect=2);

Well, nothing worked. I want the title on the top of the graph, just like what plt.title() usually do.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Dumb ML
  • 357
  • 2
  • 12
  • is `g` a matplotlib Axes, matplotlib Figure, or a seaborn Grid? – Paul H Aug 20 '20 at 17:27
  • The main answer to [How to add a title to Seaborn Facet Plot](https://stackoverflow.com/questions/29813694/how-to-add-a-title-to-seaborn-facet-plot) has been updated for current Seaborn, and there's a complete `relplot` example in it now. – cphlewis Jul 08 '21 at 21:29
  • This [answer](https://stackoverflow.com/a/42030162/7758804) in the duplicate, precedes this question. – Trenton McKinney Sep 29 '22 at 19:47

1 Answers1

4

As you failed to include the source DataFrame, I used another one:

df = sns.load_dataset("tips")

Then I created the relplot the following way:

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);

The result I got was:

enter image description here

Of course, the content of the image is different, but at least you have a title here, with the image adjusted down, to leave some space below the title.

Valdi_Bo
  • 30,023
  • 4
  • 23
  • 41