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...
or the legend in the second image
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.
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.
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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With