4

My diagram is too big.

As is

  1. The problem is the red line, which is going below 50.

In some old books I found a nice work around for this. Their the area between the main part and the outlier is left out, and replaced with a zickzack line dividing the diagram.
Can someone help me doing something like that? Maybe it is even possible to show the outlier in a magnifying glass like here!

  1. My second problem is the x-scale which should be higher, below the last point at ~20.

My code so far:

\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}

By the way, I really had fun drawing the picture! Be happy as well :)

  • 2
    For plots I woudl highly recommend you use pgfplots instead of doing them directly in tikz. Also, please convert your code snippet into a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. – Peter Grill Oct 29 '14 at 19:55
  • Hm .. so how does this work with pgfplots? I use tikzedt.org to "draw" my graph, thats why there was no documentclass. Is there something similar for pgfplots? What is the "relevant" command in pgfplots to solve this problem? – lony Oct 29 '14 at 20:32
  • For what it's worth, cutting out part of the axis is considered to be bad presentation in many cases. It distorts the relative magnitudes of the different points on your graph, so e.g. it could make the difference between 75 and 80 look much more significant than it really is. But whether this is the case with your graph depends on the interpretation of your data. – David Z Oct 29 '14 at 23:33
4

Here is the same figure with pgfplots. Doesn't seem to need to have an interrupted axis:

enter image description here

or with axis y discontinuity:

enter image description here

Code:

\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}

Code: 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}
  • Looks really nice thanks! Is it also possible to do it without adjusting the scale? I still would love to have the zickzack :) – lony Oct 29 '14 at 20:54
  • See revised solution. – Peter Grill Oct 29 '14 at 21:30
  • Very nice answer. Thanks. I have a question here. When we use discontinuity in plots, the discontinuity fills the space between y=0 and y=40. We have discontinuity sign and 40 on your plot, but I can not see zero shown on it. Even in x-axis we don't see the discontinuity sign. Is my thought correct or you are showing the correct and standard plotting in this case? – Enthusiastic Engineer Oct 29 '14 at 22:03
  • @PeterGrill thank you, amazing! That was exactly what I wanted! – lony Oct 29 '14 at 23:17
  • @EnthusiasticStudent: Have updated the solution to show the x=0 position. – Peter Grill Oct 29 '14 at 23:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.