我想将tick labels
正数设置为与负数占据相同的空间,以便对齐“ylabel”。我想避免absolute
设置位置,因为我有其他顾虑,不想这样做。我想对齐轴,有没有办法设置“y 刻度标签”以与那里有负号的情况占据相同的空间。我可以添加隐藏的负刻度标签吗?
\documentclass[]{article}
\usepackage{tikz}
\usepackage{pgf,pgfplots}
\pgfplotsset{compat=newest}
\pgfplotsset{
compat=newest,
plot coordinates/math parser=false,
every axis/.append style={
xlabel shift=0.5em,
ylabel shift=-0.5em
}}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
xlabel={XLABEL},
ylabel={YLABEL},
axis lines*=left]
\addplot+[mark=none] plot {x};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[%
xlabel={XLABEL},
ylabel={YLABEL},
ymin=0, ymax=6,
axis lines*=left]
\addplot+[mark=none] plot {x};
\end{axis}
\end{tikzpicture}
\end{document}
编辑:
我使用tikzscale
来缩放图表:
\documentclass[]{article}
\usepackage{tikz}
\usepackage{pgf,pgfplots,graphicx,subfig}
\usepackage{tikzscale}
\pgfplotsset{compat=newest}
\pgfplotsset{
compat=newest,
plot coordinates/math parser=false,
every axis/.append style={
xlabel shift=0.5em,
ylabel shift=-0.5em
}}
\begin{document}
\begin{figure}
\subfloat{\includegraphics[width=3cm,height=4cm]{plot1}}
\subfloat{\includegraphics[width=3cm,height=4cm]{plot1}}
\\
\subfloat{\includegraphics[width=3cm,height=4cm]{plot2}}
\subfloat{\includegraphics[width=3cm,height=4cm]{plot2}}
\end{figure}
\end{document}
导致此输出,其中轴未对齐,因为上图的负号
添加后trim axis left
如下scale only axis
所示:
\pgfplotsset{
compat=newest,
plot coordinates/math parser=false,
trim axis left,
scale only axis,
every axis/.append style={
xlabel shift=0.5em,
ylabel shift=-0.5em
}}
答案1
最“干净”的方法是设置,trim axis left
这样刻度标签就不会被考虑用于确定边界框,并且scale only axis
指定只考虑没有标签的轴区域来设置图的大小。这样,您的轴线将具有相同的长度,并且它们将沿 y 轴对齐:
\documentclass[]{article}
\usepackage{tikz}
\usepackage{pgf,pgfplots}
\pgfplotsset{compat=newest}
\pgfplotsset{
compat=newest,
scale only axis,
width=8cm, height=6cm,
trim axis left,
plot coordinates/math parser=false,
every axis/.append style={
xlabel shift=0.5em,
ylabel shift=-0.5em
}}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
xlabel={XLABEL},
ylabel={YLABEL},
axis lines*=left]
\addplot+[mark=none] plot {x};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[%
xlabel={XLABEL},
ylabel={YLABEL},
ymin=0, ymax=6,
axis lines*=left]
\addplot+[mark=none] plot {x};
\end{axis}
\end{tikzpicture}
\end{document}