How to add a title to Seaborn Facet Plot

前端 未结 7 883
不知归路
不知归路 2020-12-07 13:18

How do I add a title to this Seaborne plot? Let\'s give it a title \'I AM A TITLE\'.

tips = sns.load_dataset(\"tips\")
g = sns.FacetGrid(tips, col=\"sex\", r         


        
相关标签:
7条回答
  • 2020-12-07 13:59

    The answers using sns.plt.title() and sns.plt.suptitle() don't work anymore.

    Instead, you need to use matplotlib's title() function:

    import matplotlib.pyplot as plt
    sns.FacetGrid(<whatever>)
    plt.title("A title")
    
    0 讨论(0)
  • 2020-12-07 14:02

    What worked for me was:

    sns.plt.suptitle('YOUR TITLE HERE')

    0 讨论(0)
  • 2020-12-07 14:02

    The title will not be center aligned with the subplot titles. To set the position of the title you can use plt.suptitle("Title", x=center)

    In my case, my subplots were in a 2x1 grid, so I was able to use bbox = g.axes[0,0].get_position() to find the bounding box and then center=0.5*(bbox.x1+bbox.x2)

    0 讨论(0)
  • 2020-12-07 14:06

    After those lines:

    plt.subplots_adjust(top=0.9)
    g.fig.suptitle('THIS IS A TITLE, YOU BET') # can also get the figure from plt.gcf()
    

    If you add a suptitle without adjusting the axis, the seaborn facet titles overlap it.

    (With different data):

    enter image description here

    0 讨论(0)
  • 2020-12-07 14:08
    plt.suptitle("Title") 
    

    or

    plt.title("Title")
    

    This worked for me.

    0 讨论(0)
  • 2020-12-07 14:17
    g.fig.subplots_adjust(top=0.9)
    g.fig.suptitle('Title', fontsize=16)
    

    More info here: http://matplotlib.org/api/figure_api.html

    0 讨论(0)
提交回复
热议问题