3

i want to create a not continuous plot where it is possible to "jump" from 10% to e.g. 50% without a continuous scaling. I think i got most of the solution myself and will post it below. The "problem" is that i cant define the first plot group as ymin=0,ymax=6, and the second group as ymin=45,ymax=80,. When i define the first range, it displaces this part of the plot to the very right side and part of it out of the plot (and i dont unterstand why). See this picture:enter image description here When i define the second range, the plot simply "disappears", and only a white space remains on this part of the document.

Currently this looks like: enter image description here What is nearly what i want to show except that i want on the "bottom part" right part of the plot only 4 bars with the "same" height as they differ on the upper part and on the left bottom part it be possible to actually see different heighs of the bars and not like the current look. Of course in the upper part the left bars should not be shown as they have to small values.

I hope you can help me with this issue

\documentclass{ifacconf}   
\usepackage[round]{natbib} 
\usepackage{graphicx}      
\usepackage{pgfplots}  
\usetikzlibrary{pgfplots.groupplots} 
\usepackage{tikz-timing} 
\usepackage{listings} 
\usepackage{xcolor} 
\definecolor{ForestGreen}{RGB}{34,139,34} 
\definecolor{Gold}{RGB}{218,165,32} 
\definecolor{MediumBlue}{RGB}{25,25,205} 
\usepackage{capt-of} 
\begin{document} 
\pgfplotsset{ 
    every non boxed x axis/.style={}  
    } 
\begin{tikzpicture} 
\begin{groupplot}[
    group style={
        group name=my fancy plots,
        group size=1 by 2,
        xticklabels at=edge bottom,
        vertical sep=0pt
    },
    width=9.5cm,      ybar, 
      enlarge 
      x limits=0.5,
      %ylabel={\#participants}, 
      symbolic x coords={\# Variables (\%),Pipeline Utilization (\%)}, %efficiency
      xtick=data, 
      %nodes near coords,
      %nodes near coords align={vertical}, 
      %every node near coord/.append style={font=\small},
      legend style={at={(0.25,0.69)},anchor=south, cells={align=left}}, ]

\nextgroupplot[%ymin=45,ymax=80,
               ytick={60,80},
               axis x line=top, 
               axis y discontinuity=crunch,
               ybar, 
               bar width=.68cm,
               nodes near coords,
               nodes near coords align={vertical}, 
               every node near coord/.append style={font=\small},
               height=4.5cm]

      \addplot [color=purple, fill = purple,]coordinates {(\# Variables (\%),5.14) (Pipeline Utilization (\%),62.05)}; 
      \addplot [color=orange, fill = orange,]coordinates {(\# Variables (\%),4.91) (Pipeline Utilization (\%),63.53)}; 
      \addplot [color=ForestGreen, fill = ForestGreen,]coordinates {(\# Variables (\%),0.27) (Pipeline Utilization (\%),65.51)}; 
      \addplot [color=MediumBlue, fill = MediumBlue,]coordinates {(\# Variables (\%),0.33) (Pipeline Utilization (\%),66.75)};        

\nextgroupplot[%ymin=0,ymax=6,
               ytick={0},
               axis x line=bottom,
               ybar, 
               bar width=.68cm,
               height=2.0cm]

      \addplot [color=purple, fill = purple,]coordinates {(\# Variables (\%),5.14) (Pipeline Utilization (\%),62.05)}; 
      \addplot [color=orange, fill = orange,]coordinates {(\# Variables (\%),4.91) (Pipeline Utilization (\%),63.53)}; 
      \addplot [color=ForestGreen, fill = ForestGreen,]coordinates {(\# Variables (\%),0.27) (Pipeline Utilization (\%),65.51)}; 
      \addplot [color=MediumBlue, fill = MediumBlue,]coordinates {(\# Variables (\%),0.33) (Pipeline Utilization (\%),66.75)};               
\end{groupplot} 
\end{tikzpicture} 
\end{document}
Stefan Pinnow
  • 29,535
Alfred
  • 91
  • 1
  • 1
  • 2

1 Answers1

2

I think, your approach is better suited for line charts, but not for columns.

You could make use of two axes with different scales:

\documentclass{article}   
\usepackage[round]{natbib} 
\usepackage{graphicx}      
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usetikzlibrary{pgfplots.groupplots} 
\usepackage{tikz-timing} 
\usepackage{listings} 
\usepackage{xcolor} 
\definecolor{ForestGreen}{RGB}{34,139,34} 
\definecolor{Gold}{RGB}{218,165,32} 
\definecolor{MediumBlue}{RGB}{25,25,205} 
\usepackage{capt-of} 
\begin{document} 

\begin{tikzpicture} 
\pgfplotsset{
      width=95mm,
      axis x line=box,
      axis y discontinuity=crunch,
      ybar, 
      xmin=0,xmax=1,
      xtick={0,1},
      xticklabels={\# Variables (\%),Pipeline Utilization (\%)}, 
      enlarge x limits=.5,
}

\begin{axis}[%
      ymin=45, ymax=80,
      height=45mm,
      bar width=.68cm,
      ytick={60,80},
      nodes near coords,
      nodes near coords align={vertical}, 
      every node near coord/.append style={font=\small}]

      \addplot [color=purple, fill = purple,] coordinates {(1,62.05)}; 
      \addplot [color=orange, fill = orange,] coordinates {(1,63.53)}; 
      \addplot [color=ForestGreen, fill = ForestGreen,] coordinates {(1,65.51)}; 
      \addplot [color=MediumBlue, fill = MediumBlue,] coordinates {(1,66.75)}; 
\end{axis}

\begin{axis}[%
      ymin=0, ymax=6,
      height=20mm,
      bar width=.68cm,
      ytick={0},
      axis line style={draw=none},
      xticklabels={,},
      nodes near coords,
      nodes near coords align={vertical}, 
      every node near coord/.append style={font=\small}]

      \addplot [color=purple, fill = purple,]coordinates {(0,5.14)}; 
      \addplot [color=orange, fill = orange,]coordinates {(0,4.91)}; 
      \addplot [color=ForestGreen, fill = ForestGreen,]coordinates {(0,0.27)}; 
      \addplot [color=MediumBlue, fill = MediumBlue,]coordinates {(0,0.33)}; 
\end{axis}

\end{tikzpicture} 
\end{document}

enter image description here


Edit: It is currently not possible to shift the discontinuity crunch using pgfplots options. Also, there seems to exist a problem when decorations are applied to axes, especially when using pre length and post length, as documented here. Stil, I managed to draw a custom disconinuity crunch using a pathreplacing decoration that substitutes the axes. Sadly, it seems that you cannot use axis x line=box with this solution.

\documentclass{article}   
\usepackage{pgfplots}
\usetikzlibrary{decorations.pathreplacing}
\pgfplotsset{compat=1.14}
\usepackage{xcolor}
\definecolor{ForestGreen}{RGB}{34,139,34} 
\definecolor{Gold}{RGB}{218,165,32} 
\definecolor{MediumBlue}{RGB}{25,25,205} 

\begin{document} 

\begin{tikzpicture}[discontinuity/.style={decoration={show path construction,lineto code={%
        \path (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast) coordinate[pos=.3] (mid);%
        \draw (\tikzinputsegmentfirst) -- ([yshift=-6pt]mid) -- ++(-3pt,3pt) -- ++(6pt,3pt) -- ++(-3pt,3pt) -- (\tikzinputsegmentlast);%
      }}}]

\pgfplotsset{
      width=95mm,
      axis x line=bottom,
      %axis y discontinuity=crunch,
      ybar, 
      xmin=0,xmax=1,
      xtick={0,1},
      xticklabels={\# Variables (\%),Pipeline Utilization (\%)}, 
      enlarge x limits=.5,
}

\begin{axis}[%
      ymin=45, ymax=80,
      height=45mm,
      bar width=.68cm,
      ytick={60,80},
      nodes near coords,
      nodes near coords align={vertical}, 
      every node near coord/.append style={font=\small},
      every outer y axis line/.append style={discontinuity}
      ]

      \addplot [color=purple, fill = purple,] coordinates {(1,62.05)}; 
      \addplot [color=orange, fill = orange,] coordinates {(1,63.53)}; 
      \addplot [color=ForestGreen, fill = ForestGreen,] coordinates {(1,65.51)}; 
      \addplot [color=MediumBlue, fill = MediumBlue,] coordinates {(1,66.75)}; 
\end{axis}

\begin{axis}[%
      ymin=0, ymax=6,
      height=20mm,
      bar width=.68cm,
      ytick={0},
      axis line style={draw=none},
      tick style={draw=none},
      xticklabels={,},
      nodes near coords,
      nodes near coords align={vertical}, 
      every node near coord/.append style={font=\small}
      ]

      \addplot [color=purple, fill = purple,]coordinates {(0,5.14)}; 
      \addplot [color=orange, fill = orange,]coordinates {(0,4.91)}; 
      \addplot [color=ForestGreen, fill = ForestGreen,]coordinates {(0,0.27)}; 
      \addplot [color=MediumBlue, fill = MediumBlue,]coordinates {(0,0.33)}; 
\end{axis}

\end{tikzpicture} 
\end{document}

enter image description here