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?
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()
What I am getting right now:
Image 1:
What I need is something like this:
Thanks.