通过扩展仅显示 Tikz 图表的主要部分和异常值

通过扩展仅显示 Tikz 图表的主要部分和异常值

我的图太大了。

原样

  1. 问题在于红线,它已经低于 50 了。

在一些旧书中,我发现了一个很好的解决方法。它们省略了主要部分和异常值之间的区域,并用一条分割图表的 zickzack 线代替。
有人能帮我做这样的事情吗?也许甚至可以用放大镜显示异常值,就像这里

  1. 我的第二个问题是 x 尺度应该更高,低于最后一个点~20。

我迄今为止的代码:

\documentclass{article}
\usepackage{tikz}

\begin{document}

    \begin{tikzpicture}[scale=.6, xscale=0.65, yscale=0.25]
    % grid
    \draw[gray!40, thin, step=5, dotted] (0,50) grid (24,115); % Grid
    % axis
    \draw[->] (0,0) -- (25,0);
    \draw[->] (0,0) -- (0,116);
    % scale
    \foreach \x in {0,2,...,24} \draw (\x,0.05) -- (\x,-0.05) node[below] {\tiny\x};
    \foreach \y in {0,10,...,115} \draw (-0.05,\y) -- (0.05,\y) node[left] {\tiny\y};
    % lines
    \draw[blue!80!black,opacity=0.6, dashed]  (1,76.11) -- (2,114.29) -- (3,62.73) -- (4,65.75) -- (5,79.09) -- (6,76.11) -- (7,95.62) -- (8,93.83) -- (9,74.9) -- (10,85.81) -- (11,93.7) -- (12,79.75) -- (13,79.14) -- (14,87.52) -- (15,83.71) -- (16,76.74) -- (17,85.76) -- (18,81.35) -- (19,69.59) -- (20,81.74) -- (21,68.7) -- (22,74.21) -- (23,70.17) -- (24,83.33);
    \draw[red!80!black] (1,55.56) -- (2,76.02) -- (3,87.25) -- (4,96.97) -- (5,90.28) -- (6,88.64) -- (7,78.28) -- (8,80.39) -- (9,77.01) -- (10,78.13) -- (11,80.91) -- (12,85.42) -- (13,74.55) -- (14,79.91) -- (15,78.78) -- (16,77.31) -- (17,84.75) -- (18,95.84) -- (19,83.94) -- (20,86.79) -- (21,76.44) -- (22,47.76) -- (23,66.06) -- (24,24.06); 
    \end{tikzpicture}

\end{document}

顺便说一句,我画这幅画真的很开心!也要开心 :)

答案1

这是带有 的相同图形pgfplots。似乎不需要中断轴:

在此处输入图片描述

或者axis y discontinuity

在此处输入图片描述

代码:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis x line= bottom,
    axis y line= left,
    ymin = 15,
    ]
\addplot [blue!80!black,opacity=0.6, dashed, ultra thick] coordinates {
    (1,76.11)  (2,114.29)  (3,62.73)   (4,65.75)   (5,79.09)  
    (6,76.11)  (7,95.62)   (8,93.83)   (9,74.9)    (10,85.81)  
    (11,93.7)  (12,79.75)  (13,79.14)  (14,87.52)  (15,83.71)  
    (16,76.74) (17,85.76)  (18,81.35)  (19,69.59)  (20,81.74)  
    (21,68.7)  (22,74.21)  (23,70.17)  (24,83.33)
    };

\addplot [red!80!black, ultra thick] coordinates {
    (1,55.56)  (2,76.02)  (3,87.25)   (4,96.97)   (5,90.28)   
    (6,88.64)  (7,78.28)  (8,80.39)   (9,77.01)   (10,78.13)  
    (11,80.91) (12,85.42) (13,74.55)  (14,79.91)  (15,78.78)  
    (16,77.31) (17,84.75) (18,95.84)  (19,83.94)  (20,86.79)  
    (21,76.44) (22,47.76) (23,66.06)  (24,24.06)
    }; 

\end{axis}
\end{tikzpicture}

\end{document}

代码:axis y discontinuity

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis x line= bottom,
    axis y line= left,
    height=10cm, 
    ymax=120,
    xmin=0,
    axis y discontinuity=crunch,% or "parallel"
    extra tick style={major tick length=4pt}
    ]
\addplot [blue!80!black,opacity=0.6, dashed, ultra thick] coordinates {
    (1,76.11)  (2,114.29)  (3,62.73)   (4,65.75)   (5,79.09)  
    (6,76.11)  (7,95.62)   (8,93.83)   (9,74.9)    (10,85.81)  
    (11,93.7)  (12,79.75)  (13,79.14)  (14,87.52)  (15,83.71)  
    (16,76.74) (17,85.76)  (18,81.35)  (19,69.59)  (20,81.74)  
    (21,68.7)  (22,74.21)  (23,70.17)  (24,83.33)
    };

\addplot [red!80!black, ultra thick] coordinates {
    (1,55.56)  (2,76.02)  (3,87.25)   (4,96.97)   (5,90.28)   
    (6,88.64)  (7,78.28)  (8,80.39)   (9,77.01)   (10,78.13)  
    (11,80.91) (12,85.42) (13,74.55)  (14,79.91)  (15,78.78)  
    (16,77.31) (17,84.75) (18,95.84)  (19,83.94)  (20,86.79)  
    (21,76.44) (22,47.76) (23,66.06)  (24,24.06)
    }; 

\end{axis}
\end{tikzpicture}

\end{document}

相关内容