【发布时间】:2015-07-08 11:03:18
【问题描述】:
现在我正在使用 Seaborn 的集群图来生成一些集群热图 - 到目前为止一切都很好。
对于某个用例,我需要在特定单元格周围绘制彩色边框。有没有办法做到这一点?或者在 matplotlib 中使用 pcolormesh,或者任何其他方式?
【问题讨论】:
标签: python matplotlib seaborn
现在我正在使用 Seaborn 的集群图来生成一些集群热图 - 到目前为止一切都很好。
对于某个用例,我需要在特定单元格周围绘制彩色边框。有没有办法做到这一点?或者在 matplotlib 中使用 pcolormesh,或者任何其他方式?
【问题讨论】:
标签: python matplotlib seaborn
您可以通过在要突出显示的单元格上重叠绘制Rectangle patch 来做到这一点。使用seaborn docs中的示例图
import seaborn as sns
import matplotlib.pyplot as plt
sns.set()
flights = sns.load_dataset("flights")
flights = flights.pivot("month", "year", "passengers")
g = sns.clustermap(flights)
我们可以通过以下方式突出显示一个单元格
from matplotlib.patches import Rectangle
ax = g.ax_heatmap
ax.add_patch(Rectangle((3, 4), 1, 1, fill=False, edgecolor='blue', lw=3))
plt.show()
这将生成带有高亮单元格的绘图,如下所示:
请注意,单元格的索引是 0,原点位于左下角。
【讨论】: