我有一组坐标,例如
(-4, 1) (-3, 2) (-2, 3), (-1, 4)
(500, 4) (501, 3) (502, 2) (501, 1)
假设我通过这些点绘制一条插值曲线,如下所示。
\begin{tikzpicture}
\begin{axis}
\addplot[smooth, mark=*] coordinates {
(-4, 1) (-3, 2) (-2, 3), (-1, 4)
%a gap in the interpolation curve here
(500, 4) (501, 3) (502, 2) (501, 1)
};
\end{axis}
\end{tikzpicture}
问题在于,由于 x 轴的缩放/压缩,图表看起来像两条垂直线。图表旨在显示左侧斜率为正的曲线,右侧斜率为负的曲线,中间有一个间隙。因此,我想缩小/消失间隙,即 x 轴上的区间 [5, 499],并仍然适当地标记事物。
答案1
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[name=axis1, axis y line*=left, xtick=data]
\addplot[smooth, mark=*] coordinates {(-4, 1) (-3, 2) (-2, 3) (-1, 4)};
\end{axis}
\begin{axis}[at={(axis1.south east)}, axis y line*=right, yticklabels=\empty, xtick=data]
\addplot[smooth, mark=*] coordinates {(500, 4) (501, 3) (502, 2) (501, 1)};
\end{axis}
\end{tikzpicture}
\end{document}
编辑:删除正确的间隔并采用相同的 x 刻度距离
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\newcommand{\xinterval}{10}
\begin{axis}[
name=axis1,
axis y line*=left,
xmax=5, xmin=\pgfkeysvalueof{/pgfplots/xmax}-\xinterval,
]
\addplot[smooth, mark=*] coordinates {(-4, 1) (-3, 2) (-2, 3) (-1, 4)};
\end{axis}
\begin{axis}[
at={(axis1.south east)},
axis y line*=right,
yticklabels=\empty,
xmin=499, xmax=\pgfkeysvalueof{/pgfplots/xmin}+\xinterval,
]
\addplot[smooth, mark=*] coordinates {(500, 4) (501, 3) (502, 2) (501, 1)};
\end{axis}
\end{tikzpicture}
\end{document}