在以下 MWE 中,如何删除矩阵和轴之间的边距(红色箭头)?
\documentclass[margin=1cm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{3d}
\pgfplotsset{compat=1.14}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
enlargelimits=false,
axis equal,
scale only axis,
nodes near coords={\pgfmathprintnumber\pgfplotspointmeta},
every node near coord/.append style={xshift=0pt,yshift=-7pt, black, font=\scriptsize},
ytick=\empty,
xtick=\empty
]
\addplot[
matrix plot*,
point meta=explicit]
table[meta=C]{
x y C
0 0 0.0
0 1 0.0
0 2 0.3
1 0 0.0
1 1 1.0
1 2 0.0
2 0 0.0
2 1 0.0
2 2 .7
};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
以下是使用 Ti 调整边界框的一种方法钾Z 方法。不过我不确定这是否是你想要的。
\documentclass[margin=0.5cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{pgfinterruptboundingbox}
\begin{axis}[%
enlargelimits=false,
axis equal,
scale only axis,
nodes near coords={\pgfmathprintnumber\pgfplotspointmeta},
every node near coord/.append style={xshift=0pt,yshift=-7pt, black, font=\scriptsize},
ytick=\empty,
xtick=\empty
]
\addplot[
matrix plot*,
point meta=explicit]
table[meta=C]{
x y C
0 0 0.0
0 1 0.0
0 2 0.3
1 0 0.0
1 1 1.0
1 2 0.0
2 0 0.0
2 1 0.0
2 2 .7
};
\end{axis}
\end{pgfinterruptboundingbox}
\draw[use as bounding box] ([xshift=1cm,yshift=0.5cm]current axis.south west)
rectangle ([xshift=-1cm,yshift=-0.5cm]current axis.north east);
\end{tikzpicture}
\end{document}
这相当于 pgfplots 手册第 379 页中所写的内容。
\documentclass[margin=0.5cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
enlargelimits=false,
axis equal,
scale only axis,
nodes near coords={\pgfmathprintnumber\pgfplotspointmeta},
every node near coord/.append style={xshift=0pt,yshift=-7pt, black, font=\scriptsize},
ytick=\empty,
xtick=\empty
]
\addplot[
matrix plot*,
point meta=explicit]
table[meta=C]{
x y C
0 0 0.0
0 1 0.0
0 2 0.3
1 0 0.0
1 1 1.0
1 2 0.0
2 0 0.0
2 1 0.0
2 2 .7
};
\end{axis}
\pgfresetboundingbox
\draw[use as bounding box] ([xshift=1cm,yshift=0.5cm]current axis.south west)
rectangle ([xshift=-1cm,yshift=-0.5cm]current axis.north east);
\end{tikzpicture}
\end{document}