Seaborn: Passing ax kwarg to clustermap results in duplicate arguments error

Created on 12 Jan 2015  路  8Comments  路  Source: mwaskom/seaborn

Seems to be something similar to issue #414.

Working on the latest from master, I have code like this:

(figure, axes) = plt.subplots(figsize=(17,9))
axes.set_title(("Mean Monthly Temperature Cluster Map, 1894-2013\n"
                "Saint Francis, KS, USA"), fontsize=20)
_ = sns.clustermap(temps,
                   figsize=(17, 9),
                   cbar_kws={"label":
                             "Temperature\n(F)"},
                   ax=axes,
                   cmap=temps_cmap)

Which gives this error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-44-4574ed2a089c> in <module>()
      7                              "Temperature\n(F)"},
      8                    ax=axes,
----> 9                    cmap=temps_cmap)

.venv-mmpl/lib/python3.4/site-packages/seaborn/matrix.py in clustermap(data, pivot_kws, method, metric, z_score, standard_scale, figsize, cbar_kws, row_cluster, col_cluster, row_linkage, col_linkage, row_colors, col_colors, mask, **kwargs)
    898                         row_linkage=row_linkage, col_linkage=col_linkage,
    899                         mask=mask,
--> 900                         **kwargs)

.venv-mmpl/lib/python3.4/site-packages/seaborn/matrix.py in plot(self, metric, method, colorbar_kws, row_cluster, col_cluster, row_linkage, col_linkage, mask, **kws)
    816 
    817         self.plot_colors(xind, yind, **kws)
--> 818         self.plot_matrix(colorbar_kws, mask, xind, yind, **kws)
    819         return self
    820 

.venv-mmpl/lib/python3.4/site-packages/seaborn/matrix.py in plot_matrix(self, colorbar_kws, mask, xind, yind, **kws)
    797         self.data2d = self.data2d.iloc[yind, xind]
    798         heatmap(self.data2d, ax=self.ax_heatmap, cbar_ax=self.cax,
--> 799                 cbar_kws=colorbar_kws, mask=mask, **kws)
    800         self.ax_heatmap.yaxis.set_ticks_position('right')
    801         self.ax_heatmap.yaxis.set_label_position('right')

TypeError: heatmap() got multiple values for keyword argument 'ax'

Most helpful comment

Assuming you mean label the x and y axes, there's a few options. If you pass a DataFrame with names for the index and columns, those names will be used automatically. Alternatively, the clustermap function returns an object with references to the constituent axes:

g = sns.clustermap(...)
g.ax_heatmap.set_xlabel(...)

All 8 comments

ax shouldn't be getting passed through here, but this won't actually work the way you want it to anyway. clustermap is a Figure-level plot and creates its own figure and axes internally. It does take a figsize parameter to control the size of that figure, though.

Huh... I thought I saw in the docstring that ax would get passed ... help me out:

  • In clustermap, extra kwargs get passed to heatmap
  • heatmap takes an ax kwarg ...

So I'm at a bit of a loss?

Right, but a full clustermap figure has multiple axes (the main heatmap, any side-color heatmaps, the dendrograms, the colorbar, etc) and they have to be organized a particular way.

Ah, I'm looking at the ClusterMap class now and see. I'll close this and try to figure out a better way to label the top-level axes ... might just have to resort to figure.text...

Thanks!

Assuming you mean label the x and y axes, there's a few options. If you pass a DataFrame with names for the index and columns, those names will be used automatically. Alternatively, the clustermap function returns an object with references to the constituent axes:

g = sns.clustermap(...)
g.ax_heatmap.set_xlabel(...)

Sweet -- thanks!

Is there a way of inserting a clustermap within a axis, so that we can use subfigures to print two clustermaps, side-by-side?

No. A clustermap comprises multiple axes that have to be organized in a certain way.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sofiatti picture sofiatti  路  4Comments

sungshine picture sungshine  路  3Comments

TDaltonC picture TDaltonC  路  3Comments

queryous picture queryous  路  4Comments

amelio-vazquez-reina picture amelio-vazquez-reina  路  4Comments