Search code examples
python-3.xplotseaborn

Increase the font size of a Seaborn title


I have created a scatterplot using the following function:

def plot_all_seaborn(x,y,types,x_axis, y_axis, title):
    tuples = only_floats(x,y,types)
    x,y,types_new = zip(*tuples)
    frame = pd.DataFrame({x_axis:x,y_axis:y,'Model':types_new})
    sns.relplot(data=frame,
                x=x_axis, 
                y=y_axis, 
                hue="Model", 
                style="Model",
                s=500
                ).set(title=title)

For this plot, I want to increase the font size of the table. I have tried adding a font_size parameter in the set method, but this does not work. How can I enlarge the title?


Based on this link (Fine control over the font size in Seaborn plots), I tried:

def plot_all_seaborn(x,y,types,x_axis, y_axis, title):
    tuples = only_floats(x,y,types)
    x,y,types_new = zip(*tuples)
    frame = pd.DataFrame({x_axis:x,y_axis:y,'Model':types_new})
    b = sns.relplot(data=frame,
            x=x_axis, 
            y=y_axis, 
            hue="Model", 
            style="Model",
            s=500
            )
    b.set_title("Title",fontsize=20)
    plt.show()

However, this returns the following error:

AttributeError: 'FacetGrid' object has no attribute 'set_title'


Solution

  • This is doable, but you have to pass in the additional parameters as a dict.

    def plot_all_seaborn(x,y,types,x_axis, y_axis, title):
        tuples = only_floats(x,y,types)
        x,y,types_new = zip(*tuples)
        frame = pd.DataFrame({x_axis:x,y_axis:y,'Model':types_new})
        b = sns.relplot(data=frame,x=x_axis, y=y_axis)
    
        b.set_title("Title", {"fontsize"=20})
    
        plt.show()