而不是添加第二个 x 轴把它放在情节的另一边我想通过在现有轴上添加另一行刻度标签来隐式添加一个。我想要的是类似以下模型的东西:
使用这个想法这个答案我曾尝试提出类似的想法,但存在一些问题,也许有更好的方法来解决这个问题?
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{
domain=0:1,
xmin=0, xmax=1,
ymax=1, ymin=0
}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\begin{axis}[xtick align=inside,
extra x ticks={0.2, 0.4, ..., 0.8},
extra x tick labels={0.33, 0.33, 0.33, 0.33},
every extra x tick/.style={
xtick align=outside,
},
xlabel=\(x_1\),
after end axis/.code={
\node at (rel axis cs:1,0) [anchor=south west, align=left] {\(x_2\)};
}
]
\addplot{x};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
答案1
使用major tick length=0pt
样式every extra x tick
,您可以摆脱多余标签的刻度;您可以使用来防止重叠yshift
;使用您axis description
可以放置的坐标系\(x_1\)
:\(x_2\)
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{
domain=0:1,
xmin=0, xmax=1,
ymax=1, ymin=0
}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\begin{axis}[xtick align=inside,clip=false,
extra x ticks={0, 0.2, 0.4, ..., 1},
extra x tick labels={0.33, 0.33, 0.33, 0.33, 0.33,0.33},
every extra x tick/.style={major tick length=0pt,
xtick align=outside,yshift=-10pt}
]
\addplot{x};
\node at (axis description cs:0,0) [anchor=north east, align=left,xshift=-12pt] {\(x_1\)};
\node at (axis description cs:0,0) [anchor=north east, align=left,xshift=-12pt,yshift=-11pt] {\(x_2\)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}