Python 我想在matplotlib热图的列之间添加额外的空间,我该怎么做?

Python 我想在matplotlib热图的列之间添加额外的空间,我该怎么做?,python,matplotlib,heatmap,Python,Matplotlib,Heatmap,我试图在热图的列之间添加额外的空间。现在,我已经将热图的线宽设置为18,这使得“瓷砖”之间的间隙均匀,但我希望两列之间的间隙比水平间隙更宽 我查看了matplitlib.collections源代码,发现: def set_linewidth(self, lw): """ Set the linewidth(s) for the collection. *lw* can be a scalar or a seque

我试图在热图的列之间添加额外的空间。现在,我已经将热图的线宽设置为18,这使得“瓷砖”之间的间隙均匀,但我希望两列之间的间隙比水平间隙更宽

我查看了matplitlib.collections源代码,发现:

 def set_linewidth(self, lw):
        """
        Set the linewidth(s) for the collection.  *lw* can be a scalar
        or a sequence; if it is a sequence the patches will cycle
        through the sequence

        Parameters
        ----------
        lw : float or sequence of floats
        """
        if lw is None:
            lw = mpl.rcParams['patch.linewidth']
            if lw is None:
                lw = mpl.rcParams['lines.linewidth']
        # get the un-scaled/broadcast lw
        self._us_lw = np.atleast_1d(np.asarray(lw))

        # scale all of the dash patterns.
        self._linewidths, self._linestyles = self._bcast_lwls(
            self._us_lw, self._us_linestyles)
        self.stale = True
不过,似乎我在这个函数上一事无成。我试图给它一个宽度列表而不是一个变量,但是线宽只注册列表中的第一个元素

编辑: 非常感谢约翰的解决方案。 对于那些提问的人来说,这是我的代码,导致了图片中的热图

self.axes[i].pcolormesh(data,  cmap = "YlGnBu", edgecolor=BG_COLOUR, \
      linewidths=18, vmin=0.0, vmax=1.0)
以下代码是JohanC解决方案的应用

self.axes[sel].pcolormesh(data,  cmap = "YlGnBu", vmin=0.0, vmax=1.0)
for j in range(data.shape[0] + 1):
     self.axes[sel].axhline(j, color=BG_COLOUR, lw=20)
for j in range(data.shape[1] + 1):
     self.axes[sel].axvline(j, color=BG_COLOUR, lw=60)


您可以明确地绘制不同宽度的水平线和垂直线:

将numpy导入为np
将matplotlib.pyplot作为plt导入
导入seaborn作为sns
data=np.random.rand(5,2)
ax=sns.热图(数据)
对于范围内的i(data.shape[0]+1):
ax.axhline(i,color='white',lw=20)
对于范围内的i(data.shape[1]+1):
ax.axvline(i,颜色为白色,lw=60)
plt.show()

您应该粘贴代码以获取热图,而不是matplotlib的源代码,以便其他人更好地理解您的问题。具体来说,了解这些热图是否是网格模式中的6个独立热图(对于这6个热图,
gridspec
可能会有帮助),以及它们是否是单个绘图上的网格线会很有帮助。你能发布一个MWE吗?很有魅力。非常感谢:)