18

I am trying to add title on Searbon lmplot.

ax = plt.axes()
sns.lmplot(x, y, data=df, hue="hue", ax=ax)
ax.set_title("Graph (a)")
plt.show()

But I noticed that lmplot does not have an ax parameter. How can I add a title on my lmplot?

6
  • what error you are getting?
    – Akash
    Commented Sep 19, 2017 at 19:00
  • @Akash lmplot() got an unexpected keyword argument 'ax'.
    – jayko03
    Commented Sep 19, 2017 at 19:01
  • @jaykodeveloper, do you want to set a common title or one title for each subplot? Commented Sep 19, 2017 at 19:11
  • lmplots do not accept ax arguments as they return facetgrids not subplots. generally i just add plt.title("your title") Commented Sep 19, 2017 at 19:53
  • @WoodyPride it generates another empty graph. Thank you though
    – jayko03
    Commented Sep 20, 2017 at 2:45

4 Answers 4

17

try this:

sns.lmplot(x, y, data=df, hue="hue")
ax = plt.gca()
ax.set_title("Graph (a)")
1
  • 6
    This generates an empty plot with the title; the lmplot is still untitled. Commented Oct 21, 2017 at 22:34
12
# Create lmplot
lm = sns.lmplot(x, y, data=df, hue="hue", ax=ax)

# Access the figure
fig = lm.fig 

# Add a title to the Figure
fig.suptitle("My figtitle", fontsize=12)
10

seaborn uses matplotlib under the hood, so if you want a simple answer, use:

plt.title('My Title')

Right before

plt.show()
6
sns.lmplot(x, y, data=df, hue="hue", ax=ax).fig.suptitle("Graph (a)")
1
  • 2
    Perfect! Exactly what I was looking for!
    – skad00sh
    Commented Aug 28, 2020 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.