Search code examples
pythongraphgraphicsseaborn

How can i change the font-size of my seaborn.displot graphic?


I'm trying to change the font-size of my graphic title in seaborn.displot.

I have this code:

f = sns.displot(df,x="yearOfRegistration", kde=True, binwidth=5)
f.set(title = "Distribuição de Veículos com base no Ano de Registro")
f.set_axis_labels("Ano de Registro","Densidade (KDE)")

plt.show()

My output goes:

ouput

So, I tried this:

f = sns.displot(df,x="yearOfRegistration", kde=True, binwidth=5)
f.set(title = "Distribuição de Veículos com base no Ano de Registro", font_size = 20)
f.set_axis_labels("Ano de Registro","Densidade (KDE)")

plt.show()

And I have

"AttributeError: 'AxesSubplot' object has no property 'font_size'"

I've looked all over the seaborn documentation and coudn't find the solution.

Can anyone help me? Thanks!!


Solution

  • Try to use pyplot:

    from matplotlib import pyplot as plt
    
    plt.title("Title", fontdict = {'fontsize': 20})