如何轻松地在 x 轴上添加不连续性?

如何轻松地在 x 轴上添加不连续性?

我有这个简单的图表:

\documentclass[]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{positioning, decorations.pathreplacing, calc, intersections}

\begin{document}
    \begin{tikzpicture}
    \begin{axis}[
    axis lines=middle,
    xmin=-0, xmax=1000,
    ymin=0, ymax=12,
    xtick={25, 125, 250, 500, 800, 1000}, ytick={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
    ]

    \addplot [color=black,only marks, mark=x]  coordinates {
        (25, 7.5)
        (50, 8.3)
        (100, 6.1)   
        (125, 5.2)
        (250, 8.1)
        (500, 7.7)
        (800, 9.1)
        (1000, 6.3)
        (10000, 5.5)
    };
    \end{axis}
    \end{tikzpicture}

\end{document}

除最后一个点外,所有点在 x 轴上的位置都相对较近。如何才能轻松地在 x 轴上添加跳跃,以便显示最后一个坐标 (100000, 5.5)?

答案1

您可以使用groupplots,请参阅这个问题。对于您的情况,以下应该有效:

\documentclass[]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{positioning, decorations.pathreplacing, calc, intersections, pgfplots.groupplots}
\begin{document}
    \pgfplotsset{scaled x ticks=false}
    \begin{tikzpicture}    
    \begin{groupplot}[
    group style={
        group name=my fancy plots,
        group size=2 by 1,
        xticklabels at=edge bottom,
        horizontal sep=0pt
    },
    ymin=0, ymax=12,
    ytick={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
    height=8cm
    ]

    \nextgroupplot[xmin=0,xmax=1100,
    xtick={25, 125, 250, 500, 800, 1000},
    axis x line*=middle,
    axis y line=middle,
    width=11cm]
    \addplot [color=black,only marks, mark=x]  coordinates {
        (25, 7.5)
        (50, 8.3)
        (100, 6.1)   
        (125, 5.2)
        (250, 8.1)
        (500, 7.7)
        (800, 9.1)
        (1000, 6.3)
    };

    \nextgroupplot[xmin=9900,xmax=10100,
    xtick={10000},
    axis y line=none,
    axis x line=middle,
    axis x discontinuity=parallel,
    width=4cm
    ]
    \addplot [color=black,only marks, mark=x]  coordinates {
        (10000, 5.5)
    }; 
    \end{groupplot}
    \end{tikzpicture}

\end{document}

结果

答案2

我将其改为x-axis对数轴。这对您有用吗?

\documentclass[]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{positioning, decorations.pathreplacing, calc, intersections}

\begin{document}
    \begin{tikzpicture}
    \begin{axis}[
    axis lines=middle,
    xmin=0.1, xmax=10000,
    ymin=0, ymax=12,
    xmode=log,
    log ticks with fixed point,
   % xtick={25, 125, 250, 500, 800, 1000}, ytick={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
    ]

    \addplot [color=black,only marks, mark=x]  coordinates {
        (25, 7.5)
        (50, 8.3)
        (100, 6.1)   
        (125, 5.2)
        (250, 8.1)
        (500, 7.7)
        (800, 9.1)
        (1000, 6.3)
        (10000, 5.5)
    };
    \end{axis}
    \end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容