在离散热图上绘制轮廓

在离散热图上绘制轮廓

我有一个离散热图,我想绘制轮廓图来强调,例如 z > 35 的区域。您对如何实现这一点有什么建议吗?

我对热图的代码如下:

\documentclass[crop,tikz]{standalone}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[enlargelimits={false}, xtick={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}, ytick={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}, yticklabels={15,14,13,12,11,10,9,8,7,6,5,4,3,2,1}, colorbar, colormap/jet]
    \addplot+[matrix plot, mark={}, point meta={explicit}, mesh/cols={15}, mesh/rows={15}]
        coordinates {
            (1,15) [1]
            (2,15) [0]
            (3,15) [0]
            (4,15) [0]
            (5,15) [0]
            (6,15) [0]
            (7,15) [0]
            (8,15) [0]
            (9,15) [0]
            (10,15) [0]
            (11,15) [0]
            (12,15) [0]
            (13,15) [0]
            (14,15) [0]
            (15,15) [0]
            (1,14) [1]
            (2,14) [1]
            (3,14) [1]
            (4,14) [1]
            (5,14) [1]
            (6,14) [1]
            (7,14) [0]
            (8,14) [1]
            (9,14) [0]
            (10,14) [1]
            (11,14) [0]
            (12,14) [0]
            (13,14) [0]
            (14,14) [0]
            (15,14) [0]
            (1,13) [0]
            (2,13) [0]
            (3,13) [1]
            (4,13) [0]
            (5,13) [2]
            (6,13) [3]
            (7,13) [2]
            (8,13) [0]
            (9,13) [0]
            (10,13) [0]
            (11,13) [0]
            (12,13) [0]
            (13,13) [0]
            (14,13) [0]
            (15,13) [0]
            (1,12) [0]
            (2,12) [1]
            (3,12) [0]
            (4,12) [1]
            (5,12) [0]
            (6,12) [2]
            (7,12) [2]
            (8,12) [1]
            (9,12) [1]
            (10,12) [2]
            (11,12) [2]
            (12,12) [0]
            (13,12) [0]
            (14,12) [0]
            (15,12) [0]
            (1,11) [0]
            (2,11) [0]
            (3,11) [0]
            (4,11) [1]
            (5,11) [7]
            (6,11) [5]
            (7,11) [4]
            (8,11) [2]
            (9,11) [4]
            (10,11) [4]
            (11,11) [2]
            (12,11) [1]
            (13,11) [0]
            (14,11) [0]
            (15,11) [0]
            (1,10) [0]
            (2,10) [1]
            (3,10) [0]
            (4,10) [4]
            (5,10) [2]
            (6,10) [3]
            (7,10) [8]
            (8,10) [6]
            (9,10) [9]
            (10,10) [4]
            (11,10) [3]
            (12,10) [3]
            (13,10) [3]
            (14,10) [0]
            (15,10) [0]
            (1,9) [1]
            (2,9) [1]
            (3,9) [2]
            (4,9) [2]
            (5,9) [3]
            (6,9) [7]
            (7,9) [20]
            (8,9) [12]
            (9,9) [12]
            (10,9) [9]
            (11,9) [11]
            (12,9) [8]
            (13,9) [3]
            (14,9) [1]
            (15,9) [1]
            (1,8) [0]
            (2,8) [0]
            (3,8) [1]
            (4,8) [0]
            (5,8) [5]
            (6,8) [2]
            (7,8) [19]
            (8,8) [48]
            (9,8) [20]
            (10,8) [12]
            (11,8) [12]
            (12,8) [1]
            (13,8) [7]
            (14,8) [2]
            (15,8) [3]
            (1,7) [0]
            (2,7) [0]
            (3,7) [0]
            (4,7) [1]
            (5,7) [2]
            (6,7) [6]
            (7,7) [14]
            (8,7) [36]
            (9,7) [48]
            (10,7) [41]
            (11,7) [24]
            (12,7) [12]
            (13,7) [7]
            (14,7) [5]
            (15,7) [1]
            (1,6) [0]
            (2,6) [1]
            (3,6) [0]
            (4,6) [2]
            (5,6) [0]
            (6,6) [10]
            (7,6) [12]
            (8,6) [15]
            (9,6) [55]
            (10,6) [49]
            (11,6) [49]
            (12,6) [18]
            (13,6) [17]
            (14,6) [14]
            (15,6) [8]
            (1,5) [1]
            (2,5) [0]
            (3,5) [1]
            (4,5) [0]
            (5,5) [1]
            (6,5) [3]
            (7,5) [9]
            (8,5) [11]
            (9,5) [14]
            (10,5) [45]
            (11,5) [72]
            (12,5) [49]
            (13,5) [18]
            (14,5) [8]
            (15,5) [6]
            (1,4) [0]
            (2,4) [0]
            (3,4) [0]
            (4,4) [1]
            (5,4) [2]
            (6,4) [1]
            (7,4) [2]
            (8,4) [4]
            (9,4) [19]
            (10,4) [18]
            (11,4) [41]
            (12,4) [38]
            (13,4) [40]
            (14,4) [27]
            (15,4) [19]
            (1,3) [0]
            (2,3) [0]
            (3,3) [1]
            (4,3) [1]
            (5,3) [0]
            (6,3) [2]
            (7,3) [2]
            (8,3) [6]
            (9,3) [13]
            (10,3) [13]
            (11,3) [22]
            (12,3) [29]
            (13,3) [41]
            (14,3) [28]
            (15,3) [14]
            (1,2) [0]
            (2,2) [0]
            (3,2) [0]
            (4,2) [1]
            (5,2) [1]
            (6,2) [0]
            (7,2) [4]
            (8,2) [5]
            (9,2) [7]
            (10,2) [8]
            (11,2) [20]
            (12,2) [16]
            (13,2) [31]
            (14,2) [30]
            (15,2) [20]
            (1,1) [0]
            (2,1) [0]
            (3,1) [0]
            (4,1) [0]
            (5,1) [1]
            (6,1) [2]
            (7,1) [2]
            (8,1) [2]
            (9,1) [1]
            (10,1) [4]
            (11,1) [6]
            (12,1) [11]
            (13,1) [12]
            (14,1) [14]
            (15,1) [21]
        }
        ;
\end{axis}
\end{tikzpicture}

\end{document}

我想要实现的是类似这样的目标:

在此处输入图片描述

答案1

大概手工画一下:

\documentclass[crop,tikz]{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[enlargelimits={false}, xtick={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}, ytick={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}, yticklabels={15,14,13,12,11,10,9,8,7,6,5,4,3,2,1},
colorbar, colormap/jet]
\addplot+[matrix plot, mark={}, point meta={explicit}, mesh/cols={15}, mesh/rows={15}]
coordinates{
(1,15) [1]
(2,15) [0]
(3,15) [0]
(4,15) [0]
(5,15) [0]
(6,15) [0]
(7,15) [0]
(8,15) [0]
(9,15) [0]
(10,15) [0]
(11,15) [0]
(12,15) [0]
(13,15) [0]
(14,15) [0]
(15,15) [0]
(1,14) [1]
(2,14) [1]
(3,14) [1]
(4,14) [1]
(5,14) [1]
(6,14) [1]
(7,14) [0]
(8,14) [1]
(9,14) [0]
(10,14) [1]
(11,14) [0]
(12,14) [0]
(13,14) [0]
(14,14) [0]
(15,14) [0]
(1,13) [0]
(2,13) [0]
(3,13) [1]
(4,13) [0]
(5,13) [2]
(6,13) [3]
(7,13) [2]
(8,13) [0]
(9,13) [0]
(10,13) [0]
(11,13) [0]
(12,13) [0]
(13,13) [0]
(14,13) [0]
(15,13) [0]
(1,12) [0]
(2,12) [1]
(3,12) [0]
(4,12) [1]
(5,12) [0]
(6,12) [2]
(7,12) [2]
(8,12) [1]
(9,12) [1]
(10,12) [2]
(11,12) [2]
(12,12) [0]
(13,12) [0]
(14,12) [0]
(15,12) [0]
(1,11) [0]
(2,11) [0]
(3,11) [0]
(4,11) [1]
(5,11) [7]
(6,11) [5]
(7,11) [4]
(8,11) [2]
(9,11) [4]
(10,11) [4]
(11,11) [2]
(12,11) [1]
(13,11) [0]
(14,11) [0]
(15,11) [0]
(1,10) [0]
(2,10) [1]
(3,10) [0]
(4,10) [4]
(5,10) [2]
(6,10) [3]
(7,10) [8]
(8,10) [6]
(9,10) [9]
(10,10) [4]
(11,10) [3]
(12,10) [3]
(13,10) [3]
(14,10) [0]
(15,10) [0]
(1,9) [1]
(2,9) [1]
(3,9) [2]
(4,9) [2]
(5,9) [3]
(6,9) [7]
(7,9) [20]
(8,9) [12]
(9,9) [12]
(10,9) [9]
(11,9) [11]
(12,9) [8]
(13,9) [3]
(14,9) [1]
(15,9) [1]
(1,8) [0]
(2,8) [0]
(3,8) [1]
(4,8) [0]
(5,8) [5]
(6,8) [2]
(7,8) [19]
(8,8) [48]
(9,8) [20]
(10,8) [12]
(11,8) [12]
(12,8) [1]
(13,8) [7]
(14,8) [2]
(15,8) [3]
(1,7) [0]
(2,7) [0]
(3,7) [0]
(4,7) [1]
(5,7) [2]
(6,7) [6]
(7,7) [14]
(8,7) [36]
(9,7) [48]
(10,7) [41]
(11,7) [24]
(12,7) [12]
(13,7) [7]
(14,7) [5]
(15,7) [1]
(1,6) [0]
(2,6) [1]
(3,6) [0]
(4,6) [2]
(5,6) [0]
(6,6) [10]
(7,6) [12]
(8,6) [15]
(9,6) [55]
(10,6) [49]
(11,6) [49]
(12,6) [18]
(13,6) [17]
(14,6) [14]
(15,6) [8]
(1,5) [1]
(2,5) [0]
(3,5) [1]
(4,5) [0]
(5,5) [1]
(6,5) [3]
(7,5) [9]
(8,5) [11]
(9,5) [14]
(10,5) [45]
(11,5) [72]
(12,5) [49]
(13,5) [18]
(14,5) [8]
(15,5) [6]
(1,4) [0]
(2,4) [0]
(3,4) [0]
(4,4) [1]
(5,4) [2]
(6,4) [1]
(7,4) [2]
(8,4) [4]
(9,4) [19]
(10,4) [18]
(11,4) [41]
(12,4) [38]
(13,4) [40]
(14,4) [27]
(15,4) [19]
(1,3) [0]
(2,3) [0]
(3,3) [1]
(4,3) [1]
(5,3) [0]
(6,3) [2]
(7,3) [2]
(8,3) [6]
(9,3) [13]
(10,3) [13]
(11,3) [22]
(12,3) [29]
(13,3) [41]
(14,3) [28]
(15,3) [14]
(1,2) [0]
(2,2) [0]
(3,2) [0]
(4,2) [1]
(5,2) [1]
(6,2) [0]
(7,2) [4]
(8,2) [5]
(9,2) [7]
(10,2) [8]
(11,2) [20]
(12,2) [16]
(13,2) [31]
(14,2) [30]
(15,2) [20]
(1,1) [0]
(2,1) [0]
(3,1) [0]
(4,1) [0]
(5,1) [1]
(6,1) [2]
(7,1) [2]
(8,1) [2]
(9,1) [1]
(10,1) [4]
(11,1) [6]
(12,1) [11]
(13,1) [12]
(14,1) [14]
(15,1) [21]
};
\draw [red,line width=2pt] (axis cs:7.5,6.5) -- ++(0,20) -- ++(10,0) -- ++(0,-10) -- ++(20,0) -- ++(0,-10) -- ++(10,0) -- ++(0,-10) -- ++(10,0) -- ++(0,-10) -- ++(10,0) -- ++(0,-20) -- ++(-10,0) -- ++(0,10) -- ++(-20,0) -- ++(0,10) -- ++(-10,0) -- ++(0,10) -- ++(-10,0) -- ++(0,10) -- cycle;
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容