我想要将一个数据框的clustermap和box plots作为子图一起绘制。但是由于clustermap是一个figure level plot,所以我无法成功将其作为子图绘制。有没有什么办法可以实现这个目标呢?
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()
我现在得到的是:
图片1:
![enter image description here](https://istack.dev59.com/Czy1Y.webp)
图片2:
![enter image description here](https://istack.dev59.com/csBOv.webp)
![enter image description here](https://istack.dev59.com/l1jNM.webp)