0

Frustrating hour of trying to figure this out. Any idea how to show a title on a jointplot in seaborn?

title = "How long does it take to show a title with seaborn?"
g = sns.jointplot(x, y, space=0, color="b")
g.set_title = title
plt.show()

The result

Also tried:

plt.title = title


set_title(title))
Atrag
  • 653
  • 2
  • 8
  • 29
  • 3
    Does this answer your question? [How to add title to seaborn boxplot](https://stackoverflow.com/questions/42406233/how-to-add-title-to-seaborn-boxplot) – Ynjxsjmh Aug 08 '20 at 08:31

3 Answers3

3

plt.title is a method, not an attibute, so:

plt.title(title)

works, but alignment of the title is not the best:

enter image description here

However, from this question on seaborn title position

I've combined the two answers (using plt.suptitle instead of plt.title and adding a y parameter) as:

title = "How long does it take to show a title with seaborn?"
g = sns.jointplot(x, y, space=0, color="b")
plt.suptitle(title, y = 1)

and got:

enter image description here

Ujjwal Dash
  • 767
  • 1
  • 4
  • 8
dm2
  • 4,053
  • 3
  • 17
  • 28
  • plt.title(title) gave the error 'str' object is not callable but plt.suptitle("hello", y =1) worked well enough. Thank you. – Atrag Aug 08 '20 at 08:38
  • did you still have `plt.title = title` somewhere in your code by any chance ? – dm2 Aug 08 '20 at 08:40
  • No but sure enough when I print(plt.title) it comes back as the title I've set. I guess I need to reset the variables. – Atrag Aug 08 '20 at 09:00
0

I can't control the location of the title. plt.title('My title, loc='center') This was not enabled.

import numpy as np
import pandas as pd
np.random.seed(0)
import seaborn as sns
import matplotlib.pyplot as plt

sns.set(style="white", color_codes=True)
tips = sns.load_dataset("tips")
g = sns.jointplot(x="total_bill", y="tip", data=tips)

plt.title('My title')

plt.show()

enter image description here

r-beginners
  • 31,170
  • 3
  • 14
  • 32
0

Just use the method to make it work

g.set_titles(title)
Dharman
  • 30,962
  • 25
  • 85
  • 135
Mohd Kashif
  • 61
  • 1
  • 6