Seaborn clustermap within subplot
<p>I am trying to plot clustermap and box plots for a dataframe as subplots. I am having trouble plotting the clustermap as subplot as it is a figure level plot. Is there a way to achieve this?</p>

<pre><code>import pandas as pd
import seaborn as sns

# initiliaze a dataframe with index and column names
idf = pd.DataFrame.from_items([('A', [1, 2, 3]), 
                               ('B', [4, 5, 6]), 
                               ('C', [10, 20, 30]), 
                               ('D', [14, 15, 16])], 
                               orient='index', columns=['x', 'y','z'])

# Get the figure and two subplots, unpack the axes array immediately
fig, (ax1, ax2) = plt.subplots(2, sharex=True)

# Plot a boxplot in one of the subplot
idf.plot(kind='box', ax=ax1)

# Plot the clustermap in the other subplot
cax = sns.clustermap(idf, col_cluster=False, row_cluster=True)

# I tried to change the axis from the clustermap to subplot axis
# but I don't think this works like this
cax.ax_heatmap=ax2

# Show the plot
plt.show()
</code></pre>

<p>What I am getting right now:</p>

<p>Image 1:</p>

<p><a href="http://i.stack.imgur.com/Czy1Y.png" rel="nofollow"><img src="http://i.stack.imgur.com/Czy1Y.png" alt="enter image description here"></a></p>

<hr>

<p>Image 2:
<a href="http://i.stack.imgur.com/csBOv.png" rel="nofollow"><img src="http://i.stack.imgur.com/csBOv.png" alt="enter image description here"></a></p>

<p>What I need is something like this:</p>

<p><a href="http://i.stack.imgur.com/l1jNM.png" rel="nofollow"><img src="http://i.stack.imgur.com/l1jNM.png" alt="enter image description here"></a></p>

<p>Thanks.</p>

<p>You should pass the ax as argument of the clustermap function:</p>

<pre><code>cax = sns.clustermap(idf, col_cluster=False, row_cluster=True, ax = ax2)
</code></pre>

<p>As you can see from the documentation of the function clustermap (<a href="https://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.clustermap.html" rel="nofollow">https://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.clustermap.html</a>), the actual function doing the plot is heatmap <a href="https://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.heatmap.html" rel="nofollow">https://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.heatmap.html</a> which accept the ax as parameter.</p>

python matplotlib heatmap seaborn