I have searched, but not yet discovered how to add a title to a Seaborn Clustermap.
I have tried:
plt.title('Title',loc='center')
but this adds the title to the legend, rather than the main Clustermap.
I have also tried, creating an axes object first and adding the title to this (which seems to work for the Heatmap), but the problem is that the Clustermap does not plot on this axes object. It plots on its own object apparently.
Thanks for any help...
The clustermap() function of seaborn plots a hierarchically-clustered heat map of the given matrix dataset. It returns a clustered grid index.
To save a plot in Seaborn, we can use the savefig() method.
You can use .fig.suptitle('Your Title')
.
Imagine this example from the Seaborn documentation for a clustermap:
import seaborn as sns
iris = sns.load_dataset("iris")
species = iris.pop("species")
g = sns.clustermap(iris)
You add a title with:
g = sns.clustermap(iris).fig.suptitle('Your Title')
Or simply:
g.fig.suptitle('Your Title')
However, this adds a title to the whole figure and not to single subplots. If you want to add a title to a subplot, see @Kiraly Sandor's solution.
g.fig.suptitle('Figure Title')
g.ax_heatmap.set_title('Subplot Title')
One of the solutions could be this: the object returned by the plot has an ax_heatmap
method that has a set_title
method. If you set it with a title your plot will have one:
import seaborn as sns
sns.set(color_codes=True)
iris = sns.load_dataset("iris")
species = iris.pop("species")
g = sns.clustermap(iris)
g.ax_heatmap.set_title('lalal')
However this approach adds a title above your heatmap and not the whole plot.
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