pgfplots
我正在准备一个使用在'环境中生成的图表的演讲axis
。我希望图表的轴具有完全相同的大小和位置。不幸的是,具有不同轴和图表标签的图表大小不同,并且在翻阅演示文稿的页面时会产生小的“跳跃”。在下面的代码中,我说明了这个问题。轴具有相同的大小,但由于标签不同,它们的水平位置会发生变化。如果注释掉该varwidth
选项,就会发现在垂直方向上也会发生同样的事情。
\documentclass[crop,10pt,
varwidth=250pt
]{standalone}
\usepackage[english]{babel}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=200pt,
heigth=200pt,
xmin=0,xmax=1,ymin=0,ymax=1,
xlabel=xlabel,
ylabel=ylabel,
scale only axis
]
\addplot coordinates{
(0.1,0.1)
(0.9,0.9)
};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[
width=200pt,
heigth=200pt,
xmin=0,xmax=100,ymin=0,ymax=100,
xlabel=x$_l^a$bel,
ylabel=y$_l^a$bel,
scale only axis,
]
\addplot coordinates{
(10,10)
(90,90)
};
\end{axis}
\end{tikzpicture}
\end{document}
有没有办法生成具有完全相同大小和位置的轴的单独图?
答案1
我认为部分4.20 图片尺寸:边界框和裁剪手册pgfplots
(v1.10)可能会有用,您可以使用overlay
样式规范从边界框中排除部分,从而只对齐轴本身,而不管标签的大小。
\documentclass{article}
\usepackage[english]{babel}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
width=200pt,
height=200pt,
xmin=0,xmax=1,ymin=0,ymax=1,
xlabel=xlabel,
ylabel=ylabel,
ylabel style={overlay},
yticklabel style={overlay},
xlabel style={overlay},
xticklabel style={overlay},
scale only axis
]
\addplot coordinates{
(0.1,0.1)
(0.9,0.9)
};
\end{axis}
\end{tikzpicture}
\end{center}
\vspace*{4em}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
width=200pt,
height=200pt,
xmin=0,xmax=100,ymin=0,ymax=100,
xlabel=x$_l^a$bel,
ylabel=y$_l^a$bel,
ylabel style={overlay},
yticklabel style={overlay},
xlabel style={overlay},
xticklabel style={overlay},
scale only axis,
]
\addplot coordinates{
(10,10)
(90,90)
};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
答案2
感谢@hugovdberg,我找到了解决方案。可以使用库calc
定义相对于绘图轴的坐标,然后使用它\path[use as bounding box] (first coordinate) rectangle (second coordinate);
来创建边界框。以下代码将产生所需的结果。绘制边界框是为了说明。
\documentclass[10pt]{beamer}
\usepackage[english]{babel}
\usepackage{pgfplots}
\usetikzlibrary{calc}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\begin{axis}[
width=150pt,
height=150pt,
xmin=0,xmax=1,ymin=0,ymax=1,
xlabel=xlabel,
ylabel=ylabel,
scale only axis,
]
\addplot coordinates{
(0.1,0.1)
(0.9,0.9)
};
\end{axis}
\coordinate (topleft) at ($(current axis.north west) + (-1.3cm,0.3cm)$);
\coordinate (bottomright) at ($(current axis.south east) + (0.4cm,-1cm)$);
\path[use as bounding box,draw] (topleft) rectangle (bottomright);
\end{tikzpicture}
\end{frame}
\begin{frame}
\begin{tikzpicture}
\begin{axis}[
width=150pt,
height=150pt,
xmin=0,xmax=100,ymin=0,ymax=100,
xlabel=x$_l^a$bel,
ylabel=y$_l^a$bel,
scale only axis,
]
\addplot coordinates{
(10,10)
(90,90)
};
\end{axis}
\coordinate (topleft) at ($(current axis.north west) + (-1.3cm,0.3cm)$);
\coordinate (bottomright) at ($(current axis.south east) + (0.4cm,-1cm)$);
\path[use as bounding box,draw] (topleft) rectangle (bottomright);
\end{tikzpicture}
\end{frame}
\end{document}