Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the title of factor plot in seaborn

Does anyone know how to change the legend and the title in seaborn? See the below. I kind of want to change the name "Gaussia" to "Guassian Naive Bayes" etc...enter image description here
enter image description hereor the legend in the second image

like image 664
MYjx Avatar asked Jul 16 '14 20:07

MYjx


People also ask

How do I add a title to Seaborn FacetGrid?

If you create the FacetGrid directly, as in the original example, it automatically adds column and row labels instead of individual subplot titles. We can still add a title to the whole thing: from matplotlib. pyplot import scatter as plt_scatter g = sns.

What is Factorplot in Seaborn?

Factor Plot is used to draw a different types of categorical plot . The default plot that is shown is a point plot, but we can plot other seaborn categorical plots by using of kind parameter, like box plots, violin plots, bar plots, or strip plots.

How do you label a graph in Seaborn?

Use the set_xlabel() and set_ylabel() Functions to Set the Axis Labels in a Seaborn Plot. A seaborn plot returns a matplotlib axes instance type object. We can use the set_xlabel() and set_ylabel to set the x and y-axis label respectively. We can use the fontsize parameter to control the size of the font.

How do you add a legend title in Seaborn?

By default, seaborn automatically adds a legend to the graph. Notice the legend is at the top right corner. If we want to explicitly add a legend, we can use the legend() function from the matplotlib library.


1 Answers

These values are just taken from the field in the input DataFrame that you use as the col or hue variable in the factorgrid plot. So the correct thing to do would be to set the values as you want them in the original DataFrame and then pass that to seaborn.factorplot.

Alternatively, once you have plotted, the function returns an object of class FacetGrid that has a method called set_titles. This allows you to change the titles after plotting more flexibly, but it also is fundamentally based on the values in the DataFrame you passed into the function. See the docstring of that method for more detal.

The final option is to set the titles manually using matplotlib commands. The FacetGrid object that gets returned also has an axes attribute, which is a 2 dimensional array of the maptlotlib Axes in the figure. You can loop through this and set the titles to whatever you want:

g = sns.factorplot(...)
titles = ["foo", "bar", "buz"]
for ax, title in zip(g.axes.flat, titles):
    ax.set_title(title)
like image 198
mwaskom Avatar answered Oct 28 '22 15:10

mwaskom