删除轴周围的空白

删除轴周围的空白

我希望我的图尽可能地填充给定的图形,但找不到如何去除轴节点周围的空白。我已经将 tikzpicture 和轴的内外分离设置为零,但空间仍然存在。

我期望是这样的:

以下是创建该图形的 MWE:

\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\DeclareUnicodeCharacter{2212}{−}
\usepgfplotslibrary{groupplots,dateplot}
\usetikzlibrary{patterns,shapes.arrows}
\usetikzlibrary{backgrounds}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}[framed,outer sep=0pt, inner sep=0pt]%
\begin{axis}[%
every axis label/.append style={draw},
inner sep=0pt,
outer sep=0pt,
height=5cm,
width=5cm,
tick align=outside,
tick pos=left,
label style={inner sep=0pt},
tick label style={inner sep=1pt},
xlabel={xaxis},
ylabel={yaxis}
]%
\end{axis}%
\end{tikzpicture}%
\end{document}%

答案1

填充来自framedtikzpicture环境的选项。您可以删除此选项,也可以输入以下命令inner frame sep=0pt来删除填充:

\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\DeclareUnicodeCharacter{2212}{−}
\usepgfplotslibrary{groupplots,dateplot}
\usetikzlibrary{patterns,shapes.arrows}
\usetikzlibrary{backgrounds}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}[framed, inner frame sep=0pt]%
\begin{axis}[%
every axis label/.append style={draw},
inner sep=0pt,
outer sep=0pt,
height=5cm,
width=5cm,
tick align=outside,
tick pos=left,
label style={inner sep=0pt},
tick label style={inner sep=1pt},
xlabel={xaxis},
ylabel={yaxis}
]%
\end{axis}%
\end{tikzpicture}%
\end{document}%

在此处输入图片描述

摘录自Z & PGF 手册

在此处输入图片描述

答案2

没有axis额外空间,但背景框架有 - 使用选项tight background

\documentclass[border=0cm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{backgrounds}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}[background rectangle/.style={draw=red, thick}, framed, tight background]
\begin{axis}
\end{axis}
\end{tikzpicture}
\end{document}

带有红色边框的空图表

相关内容