绘图时缩小图形

绘图时缩小图形

此矩阵图比应有的长度多了一个方格。我不明白这是什么原因造成的。

图像

这是完整的代码:

\documentclass[border=5mm]{standalone}

\usepackage{pgfplots}
\begin{document}

\pgfplotsset{
    matrix plot/.style={
        axis on top,
        clip marker paths=true,
        scale only axis,
        height=\matrixrows/\matrixcols*\pgfkeysvalueof{/pgfplots/width},
        enlarge x limits={rel=0.5/\matrixcols},
        enlarge y limits={rel=0.5/\matrixrows},
        scatter/use mapped color={draw=mapped color, fill=mapped color},
        scatter,
        point meta=explicit,
        mark=square*,
        cycle list={
            mark size=0.5*\pgfkeysvalueof{/pgfplots/width}/\matrixcols
        }
    },
    matrix rows/.store in=\matrixrows,
    matrix rows=10,
    matrix cols/.store in=\matrixcols,
    matrix cols=10
}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
width=9cm, 
matrix plot,
colormap/bluered,
colorbar
]
\addplot table [meta=Data] {
Pos1    Pos2    Data
0.5 0.5 0
0.5 1.5 1.29
0.5 2.5 9.06
0.5 3.5 3.01
0.5 4.5 3.15
0.5 5.5 7.17
0.5 6.5 -4.03
0.5 7.5 4.92
0.5 8.5 -3.63
0.5 9.5 0.43
0.5 10.5    14.6
0.5 11.5    4.87
0.5 12.5    -4.31
0.5 13.5    3.39
0.5 14.5    4
0.5 15.5    3.24
0.5 16.5    0.07
0.5 17.5    -2.26
1.5 0.5 1.29
1.5 1.5 0
1.5 2.5 0.45
1.5 3.5 -3.43
1.5 4.5 -11.58
1.5 5.5 -7.69
1.5 6.5 17.88
1.5 7.5 -4.78
1.5 8.5 -7.87
1.5 9.5 1.72
1.5 10.5    35.19
1.5 11.5    -2.28
1.5 12.5    6.3
1.5 13.5    1.89
1.5 14.5    1.16
1.5 15.5    11.67
1.5 16.5    3.52
1.5 17.5    7.73
2.5 0.5 9.06
2.5 1.5 0.45
2.5 2.5 0
2.5 3.5 9.8
2.5 4.5 11.36
2.5 5.5 10.57
2.5 6.5 12.58
2.5 7.5 9.67
2.5 8.5 2.24
2.5 9.5 9.31
2.5 10.5    21.85
2.5 11.5    8.72
2.5 12.5    9.48
2.5 13.5    10.56
2.5 14.5    12.21
2.5 15.5    -1.79
2.5 16.5    13.7
2.5 17.5    11.98
3.5 0.5 3.01
3.5 1.5 -3.43
3.5 2.5 9.8
3.5 3.5 0
3.5 4.5 7.86
3.5 5.5 5.7
3.5 6.5 -4.51
3.5 7.5 -2.67
3.5 8.5 8.11
3.5 9.5 -4.02
3.5 10.5    19.33
3.5 11.5    -4.16
3.5 12.5    -12.27
3.5 13.5    -2.04
3.5 14.5    -3.45
3.5 15.5    3.85
3.5 16.5    -3.82
3.5 17.5    -10.67
4.5 0.5 3.15
4.5 1.5 -11.58
4.5 2.5 11.36
4.5 3.5 7.86
4.5 4.5 0
4.5 5.5 -2.33
4.5 6.5 -31.33
4.5 7.5 -3.19
4.5 8.5 9.05
4.5 9.5 -12.2
4.5 10.5    11.37
4.5 11.5    0.3
4.5 12.5    -11.4
4.5 13.5    -6.33
4.5 14.5    -8.55
4.5 15.5    1.02
4.5 16.5    -19.13
4.5 17.5    -19.3
5.5 0.5 7.17
5.5 1.5 -7.69
5.5 2.5 10.57
5.5 3.5 5.7
5.5 4.5 -2.33
5.5 5.5 0
5.5 6.5 -24.3
5.5 7.5 10.88
5.5 8.5 -1.69
5.5 9.5 3.73
5.5 10.5    17.9
5.5 11.5    5.06
5.5 12.5    -2.28
5.5 13.5    4.51
5.5 14.5    1.75
5.5 15.5    16.57
5.5 16.5    -6.58
5.5 17.5    -14.1
6.5 0.5 -4.03
6.5 1.5 17.88
6.5 2.5 12.58
6.5 3.5 -4.51
6.5 4.5 -31.33
6.5 5.5 -24.3
6.5 6.5 0
6.5 7.5 -5.97
6.5 8.5 -24.5
6.5 9.5 -3.11
6.5 10.5    19.45
6.5 11.5    -1.02
6.5 12.5    3.14
6.5 13.5    5.44
6.5 14.5    -57.9
6.5 15.5    13.36
6.5 16.5    17.54
6.5 17.5    11.2
7.5 0.5 4.92
7.5 1.5 -4.78
7.5 2.5 9.67
7.5 3.5 -2.67
7.5 4.5 -3.19
7.5 5.5 10.88
7.5 6.5 -5.97
7.5 7.5 0
7.5 8.5 -2.16
7.5 9.5 0.54
7.5 10.5    21.73
7.5 11.5    7.18
7.5 12.5    -4.8
7.5 13.5    11.63
7.5 14.5    18.92
7.5 15.5    13.26
7.5 16.5    22.91
7.5 17.5    -6.7
8.5 0.5 -3.63
8.5 1.5 -7.87
8.5 2.5 2.24
8.5 3.5 8.11
8.5 4.5 9.05
8.5 5.5 -1.69
8.5 6.5 -24.5
8.5 7.5 -2.16
8.5 8.5 0
8.5 9.5 -7.79
8.5 10.5    18.81
8.5 11.5    -0.53
8.5 12.5    -10.08
8.5 13.5    -3.09
8.5 14.5    -6.53
8.5 15.5    2.12
8.5 16.5    -15.43
8.5 17.5    -16.6
9.5 0.5 0.43
9.5 1.5 1.72
9.5 2.5 9.31
9.5 3.5 -4.02
9.5 4.5 -12.2
9.5 5.5 3.73
9.5 6.5 -3.11
9.5 7.5 0.54
9.5 8.5 -7.79
9.5 9.5 0
9.5 10.5    22.03
9.5 11.5    0.05
9.5 12.5    3.46
9.5 13.5    6.53
9.5 14.5    6.52
9.5 15.5    11.43
9.5 16.5    -3.72
9.5 17.5    3.65
10.5    0.5 14.6
10.5    1.5 35.19
10.5    2.5 21.85
10.5    3.5 19.33
10.5    4.5 11.37
10.5    5.5 17.9
10.5    6.5 19.45
10.5    7.5 21.73
10.5    8.5 18.81
10.5    9.5 22.03
10.5    10.5    0
10.5    11.5    20.84
10.5    12.5    18.32
10.5    13.5    19.07
10.5    14.5    16.68
10.5    15.5    22.01
10.5    16.5    14.86
10.5    17.5    14.44
11.5    0.5 4.87
11.5    1.5 -2.28
11.5    2.5 8.72
11.5    3.5 -4.16
11.5    4.5 0.3
11.5    5.5 5.06
11.5    6.5 -1.02
11.5    7.5 7.18
11.5    8.5 -0.53
11.5    9.5 0.05
11.5    10.5    20.84
11.5    11.5    0
11.5    12.5    -1.54
11.5    13.5    4.48
11.5    14.5    2.18
11.5    15.5    4.81
11.5    16.5    2.65
11.5    17.5    -2.39
12.5    0.5 -4.31
12.5    1.5 6.3
12.5    2.5 9.48
12.5    3.5 -12.27
12.5    4.5 -11.4
12.5    5.5 -2.28
12.5    6.5 3.14
12.5    7.5 -4.8
12.5    8.5 -10.08
12.5    9.5 3.46
12.5    10.5    18.32
12.5    11.5    -1.54
12.5    12.5    0
12.5    13.5    1.52
12.5    14.5    6.36
12.5    15.5    7.36
12.5    16.5    -5.22
12.5    17.5    -6.34
13.5    0.5 3.39
13.5    1.5 1.89
13.5    2.5 10.56
13.5    3.5 -2.04
13.5    4.5 -6.33
13.5    5.5 4.51
13.5    6.5 5.44
13.5    7.5 11.63
13.5    8.5 -3.09
13.5    9.5 6.53
13.5    10.5    19.07
13.5    11.5    4.48
13.5    12.5    1.52
13.5    13.5    0
13.5    14.5    5.22
13.5    15.5    10.3
13.5    16.5    3.73
13.5    17.5    -2.03
14.5    0.5 4
14.5    1.5 1.16
14.5    2.5 12.21
14.5    3.5 -3.45
14.5    4.5 -8.55
14.5    5.5 1.75
14.5    6.5 -57.9
14.5    7.5 18.92
14.5    8.5 -6.53
14.5    9.5 6.52
14.5    10.5    16.68
14.5    11.5    2.18
14.5    12.5    6.36
14.5    13.5    5.22
14.5    14.5    0
14.5    15.5    11.19
14.5    16.5    9.5
14.5    17.5    -7.13
15.5    0.5 3.24
15.5    1.5 11.67
15.5    2.5 -1.79
15.5    3.5 3.85
15.5    4.5 1.02
15.5    5.5 16.57
15.5    6.5 13.36
15.5    7.5 13.26
15.5    8.5 2.12
15.5    9.5 11.43
15.5    10.5    22.01
15.5    11.5    4.81
15.5    12.5    7.36
15.5    13.5    10.3
15.5    14.5    11.19
15.5    15.5    0
15.5    16.5    16.55
15.5    17.5    11.84
16.5    0.5 0.07
16.5    1.5 3.52
16.5    2.5 13.7
16.5    3.5 -3.82
16.5    4.5 -19.13
16.5    5.5 -6.58
16.5    6.5 17.54
16.5    7.5 22.91
16.5    8.5 -15.43
16.5    9.5 -3.72
16.5    10.5    14.86
16.5    11.5    2.65
16.5    12.5    -5.22
16.5    13.5    3.73
16.5    14.5    9.5
16.5    15.5    16.55
16.5    16.5    0
16.5    17.5    2.72
17.5    0.5 -2.26
17.5    1.5 7.73
17.5    2.5 11.98
17.5    3.5 -10.67
17.5    4.5 -19.3
17.5    5.5 -14.1
17.5    6.5 11.2
17.5    7.5 -6.7
17.5    8.5 -16.6
17.5    9.5 3.65
17.5    10.5    14.44
17.5    11.5    -2.39
17.5    12.5    -6.34
17.5    13.5    -2.03
17.5    14.5    -7.13
17.5    15.5    11.84
17.5    16.5    2.72
17.5    17.5    0

};

\end{document}

答案1

这是因为您的数据有 18 行/列,但您有

matrix cols/.store in=\matrixcols,
matrix cols=10

mark size=0.5*\pgfkeysvalueof{/pgfplots/width}/\matrixcols

结果,标记几乎是应有大小的两倍,并且绘图是错误的。同时设置matrix cols=18matrix rows=18,您将得到

在此处输入图片描述

\documentclass[border=5mm]{standalone}

\usepackage{pgfplots}
\begin{document}

\pgfplotsset{
    matrix plot/.style={
        axis on top,
        clip marker paths=true,
        scale only axis,
        height=\matrixrows/\matrixcols*\pgfkeysvalueof{/pgfplots/width},
        enlarge x limits={rel=0.5/\matrixcols},
        enlarge y limits={rel=0.5/\matrixrows},
        scatter/use mapped color={draw=mapped color, fill=mapped color},
        scatter,
        point meta=explicit,
        mark=square*,
        cycle list={
            mark size=0.5*\pgfkeysvalueof{/pgfplots/width}/\matrixcols
        }
    },
    matrix rows/.store in=\matrixrows,
    matrix rows=18,
    matrix cols/.store in=\matrixcols,
    matrix cols=18
}

\begin{tikzpicture}
\begin{axis}[
width=9cm, 
matrix plot,
colormap/bluered,
colorbar
]
\addplot table [meta=Data] {
Pos1    Pos2    Data
0.5 0.5 0
0.5 1.5 1.29
0.5 2.5 9.06
0.5 3.5 3.01
0.5 4.5 3.15
0.5 5.5 7.17
0.5 6.5 -4.03
0.5 7.5 4.92
0.5 8.5 -3.63
0.5 9.5 0.43
0.5 10.5    14.6
0.5 11.5    4.87
0.5 12.5    -4.31
0.5 13.5    3.39
0.5 14.5    4
0.5 15.5    3.24
0.5 16.5    0.07
0.5 17.5    -2.26
1.5 0.5 1.29
1.5 1.5 0
1.5 2.5 0.45
1.5 3.5 -3.43
1.5 4.5 -11.58
1.5 5.5 -7.69
1.5 6.5 17.88
1.5 7.5 -4.78
1.5 8.5 -7.87
1.5 9.5 1.72
1.5 10.5    35.19
1.5 11.5    -2.28
1.5 12.5    6.3
1.5 13.5    1.89
1.5 14.5    1.16
1.5 15.5    11.67
1.5 16.5    3.52
1.5 17.5    7.73
2.5 0.5 9.06
2.5 1.5 0.45
2.5 2.5 0
2.5 3.5 9.8
2.5 4.5 11.36
2.5 5.5 10.57
2.5 6.5 12.58
2.5 7.5 9.67
2.5 8.5 2.24
2.5 9.5 9.31
2.5 10.5    21.85
2.5 11.5    8.72
2.5 12.5    9.48
2.5 13.5    10.56
2.5 14.5    12.21
2.5 15.5    -1.79
2.5 16.5    13.7
2.5 17.5    11.98
3.5 0.5 3.01
3.5 1.5 -3.43
3.5 2.5 9.8
3.5 3.5 0
3.5 4.5 7.86
3.5 5.5 5.7
3.5 6.5 -4.51
3.5 7.5 -2.67
3.5 8.5 8.11
3.5 9.5 -4.02
3.5 10.5    19.33
3.5 11.5    -4.16
3.5 12.5    -12.27
3.5 13.5    -2.04
3.5 14.5    -3.45
3.5 15.5    3.85
3.5 16.5    -3.82
3.5 17.5    -10.67
4.5 0.5 3.15
4.5 1.5 -11.58
4.5 2.5 11.36
4.5 3.5 7.86
4.5 4.5 0
4.5 5.5 -2.33
4.5 6.5 -31.33
4.5 7.5 -3.19
4.5 8.5 9.05
4.5 9.5 -12.2
4.5 10.5    11.37
4.5 11.5    0.3
4.5 12.5    -11.4
4.5 13.5    -6.33
4.5 14.5    -8.55
4.5 15.5    1.02
4.5 16.5    -19.13
4.5 17.5    -19.3
5.5 0.5 7.17
5.5 1.5 -7.69
5.5 2.5 10.57
5.5 3.5 5.7
5.5 4.5 -2.33
5.5 5.5 0
5.5 6.5 -24.3
5.5 7.5 10.88
5.5 8.5 -1.69
5.5 9.5 3.73
5.5 10.5    17.9
5.5 11.5    5.06
5.5 12.5    -2.28
5.5 13.5    4.51
5.5 14.5    1.75
5.5 15.5    16.57
5.5 16.5    -6.58
5.5 17.5    -14.1
6.5 0.5 -4.03
6.5 1.5 17.88
6.5 2.5 12.58
6.5 3.5 -4.51
6.5 4.5 -31.33
6.5 5.5 -24.3
6.5 6.5 0
6.5 7.5 -5.97
6.5 8.5 -24.5
6.5 9.5 -3.11
6.5 10.5    19.45
6.5 11.5    -1.02
6.5 12.5    3.14
6.5 13.5    5.44
6.5 14.5    -57.9
6.5 15.5    13.36
6.5 16.5    17.54
6.5 17.5    11.2
7.5 0.5 4.92
7.5 1.5 -4.78
7.5 2.5 9.67
7.5 3.5 -2.67
7.5 4.5 -3.19
7.5 5.5 10.88
7.5 6.5 -5.97
7.5 7.5 0
7.5 8.5 -2.16
7.5 9.5 0.54
7.5 10.5    21.73
7.5 11.5    7.18
7.5 12.5    -4.8
7.5 13.5    11.63
7.5 14.5    18.92
7.5 15.5    13.26
7.5 16.5    22.91
7.5 17.5    -6.7
8.5 0.5 -3.63
8.5 1.5 -7.87
8.5 2.5 2.24
8.5 3.5 8.11
8.5 4.5 9.05
8.5 5.5 -1.69
8.5 6.5 -24.5
8.5 7.5 -2.16
8.5 8.5 0
8.5 9.5 -7.79
8.5 10.5    18.81
8.5 11.5    -0.53
8.5 12.5    -10.08
8.5 13.5    -3.09
8.5 14.5    -6.53
8.5 15.5    2.12
8.5 16.5    -15.43
8.5 17.5    -16.6
9.5 0.5 0.43
9.5 1.5 1.72
9.5 2.5 9.31
9.5 3.5 -4.02
9.5 4.5 -12.2
9.5 5.5 3.73
9.5 6.5 -3.11
9.5 7.5 0.54
9.5 8.5 -7.79
9.5 9.5 0
9.5 10.5    22.03
9.5 11.5    0.05
9.5 12.5    3.46
9.5 13.5    6.53
9.5 14.5    6.52
9.5 15.5    11.43
9.5 16.5    -3.72
9.5 17.5    3.65
10.5    0.5 14.6
10.5    1.5 35.19
10.5    2.5 21.85
10.5    3.5 19.33
10.5    4.5 11.37
10.5    5.5 17.9
10.5    6.5 19.45
10.5    7.5 21.73
10.5    8.5 18.81
10.5    9.5 22.03
10.5    10.5    0
10.5    11.5    20.84
10.5    12.5    18.32
10.5    13.5    19.07
10.5    14.5    16.68
10.5    15.5    22.01
10.5    16.5    14.86
10.5    17.5    14.44
11.5    0.5 4.87
11.5    1.5 -2.28
11.5    2.5 8.72
11.5    3.5 -4.16
11.5    4.5 0.3
11.5    5.5 5.06
11.5    6.5 -1.02
11.5    7.5 7.18
11.5    8.5 -0.53
11.5    9.5 0.05
11.5    10.5    20.84
11.5    11.5    0
11.5    12.5    -1.54
11.5    13.5    4.48
11.5    14.5    2.18
11.5    15.5    4.81
11.5    16.5    2.65
11.5    17.5    -2.39
12.5    0.5 -4.31
12.5    1.5 6.3
12.5    2.5 9.48
12.5    3.5 -12.27
12.5    4.5 -11.4
12.5    5.5 -2.28
12.5    6.5 3.14
12.5    7.5 -4.8
12.5    8.5 -10.08
12.5    9.5 3.46
12.5    10.5    18.32
12.5    11.5    -1.54
12.5    12.5    0
12.5    13.5    1.52
12.5    14.5    6.36
12.5    15.5    7.36
12.5    16.5    -5.22
12.5    17.5    -6.34
13.5    0.5 3.39
13.5    1.5 1.89
13.5    2.5 10.56
13.5    3.5 -2.04
13.5    4.5 -6.33
13.5    5.5 4.51
13.5    6.5 5.44
13.5    7.5 11.63
13.5    8.5 -3.09
13.5    9.5 6.53
13.5    10.5    19.07
13.5    11.5    4.48
13.5    12.5    1.52
13.5    13.5    0
13.5    14.5    5.22
13.5    15.5    10.3
13.5    16.5    3.73
13.5    17.5    -2.03
14.5    0.5 4
14.5    1.5 1.16
14.5    2.5 12.21
14.5    3.5 -3.45
14.5    4.5 -8.55
14.5    5.5 1.75
14.5    6.5 -57.9
14.5    7.5 18.92
14.5    8.5 -6.53
14.5    9.5 6.52
14.5    10.5    16.68
14.5    11.5    2.18
14.5    12.5    6.36
14.5    13.5    5.22
14.5    14.5    0
14.5    15.5    11.19
14.5    16.5    9.5
14.5    17.5    -7.13
15.5    0.5 3.24
15.5    1.5 11.67
15.5    2.5 -1.79
15.5    3.5 3.85
15.5    4.5 1.02
15.5    5.5 16.57
15.5    6.5 13.36
15.5    7.5 13.26
15.5    8.5 2.12
15.5    9.5 11.43
15.5    10.5    22.01
15.5    11.5    4.81
15.5    12.5    7.36
15.5    13.5    10.3
15.5    14.5    11.19
15.5    15.5    0
15.5    16.5    16.55
15.5    17.5    11.84
16.5    0.5 0.07
16.5    1.5 3.52
16.5    2.5 13.7
16.5    3.5 -3.82
16.5    4.5 -19.13
16.5    5.5 -6.58
16.5    6.5 17.54
16.5    7.5 22.91
16.5    8.5 -15.43
16.5    9.5 -3.72
16.5    10.5    14.86
16.5    11.5    2.65
16.5    12.5    -5.22
16.5    13.5    3.73
16.5    14.5    9.5
16.5    15.5    16.55
16.5    16.5    0
16.5    17.5    2.72
17.5    0.5 -2.26
17.5    1.5 7.73
17.5    2.5 11.98
17.5    3.5 -10.67
17.5    4.5 -19.3
17.5    5.5 -14.1
17.5    6.5 11.2
17.5    7.5 -6.7
17.5    8.5 -16.6
17.5    9.5 3.65
17.5    10.5    14.44
17.5    11.5    -2.39
17.5    12.5    -6.34
17.5    13.5    -2.03
17.5    14.5    -7.13
17.5    15.5    11.84
17.5    16.5    2.72
17.5    17.5    0

};
\end{axis}
\end{tikzpicture}
\end{document}

相关内容