2

I've found the answer to my question here. Nevertheless I have a related question. The MWE can be exactly the answer to the linked question, so I insert here just the "interested part" (if I have to copy the whole code, just tell me)

\nextgroupplot[ymin=45,ymax=80,
               ytick={60,80},
               axis x line=top, 
               axis y discontinuity=parallel,
               height=4.5cm]
\addplot {x*0};     
\addplot {x^2+50};         

\nextgroupplot[ymin=0,ymax=5,
               ytick={0},
               axis x line=bottom,
               height=2.0cm]
\addplot {x*0};     
\addplot {x^2+50};   

There's point that is not clear to me. I read ymin=45,ymax=80 in the first group and ymin=0,ymax=5 in the second one so that the ratio between the two ranges is 7. As a consequence, I would have expected the two heights to be specified such that their ratio was exactly 7. This is not the case. Can anyone explain the reason to me? How should I chose the two height parameters in relation (if they are related!) to the y ranges of the two plots in order to get same unitary lenghts?

2
  • I don't see that you would necessarily always want the same unit length. That would depend entirely on the data you're plotting, and the scales they're varying on. Commented Dec 19, 2015 at 9:25
  • @TorbjørnT. I think if it's a diagram with a axis discontinuity then it's "necessary". Commented Dec 20, 2015 at 8:35

1 Answer 1

3

I think it was just trial and error in the cited question/answer. But I generated an "analytic" approach:

Code

\documentclass{article}  
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usetikzlibrary{pgfplots.groupplots}

\begin{document}
\pgfplotsset{
% override style for non-boxed plots
    % which is the case for both sub-plots
    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=8.5cm,
        height=6.5cm,
        xmin=-6, 
        xmax=6,
        scale only axis = true,
        enlargelimits=false,
                    ]
        % top diagram           
        \nextgroupplot[
                        ymin=50,
                        ymax=100,
                        ytick={50,60,75,100},
                        axis x line=top, 
                        axis y discontinuity=parallel,
                        height=5cm,
                        axis y line=right,
                        ymajorgrids=true,
                       ]  
        % red line
        \addplot+[red,no markers,line width=2pt]{x^2+50};  
        % bottom diagram           
        \nextgroupplot[
                        ymin=0,
                        ymax=10,
                        ytick={0,10},
                        axis x line=bottom,
                        height=1cm
                       ]
        % blue line                    
        \addplot+[blue,no markers,line width=2pt]{x*0};           
    \end{groupplot}
\end{tikzpicture}

\end{document}

Output

enter image description here

Proof

I also added a "proof" that the distances (the scaling, the scale) are equally in the top and bottom diagram.

enter image description here

Explanation

  • The important code part is scale only axis = true and enlargelimits=false. Here's a cite from the pgfplots manual.

If scale only axis is enabled, width and height apply only to the axis rectangle. Consequently, the resulting figure is larger that width and height (because of any axis descriptions). However, the axis box has exactly the prescribed target dimensions.

  • Now you have control of the scaling.
  • I chose a range of 50 to 100 in the top diagram.
  • I chose a range of 0 to 10 in the bottom diagram.
  • The ratio of the heights should be (100-50)/(10-0)=5.
  • The top diagram therefore has a height of 5 cm and the bottom has a height of 1 cm.
  • I added a proof (see second picture). The height for the bottom diagram is set to 1 cm (10 mm) and I measured it in Adobe Acrobat. As you can see the axis is exactly 10 mm high. In addition you can see that a delta in y of 10 is also 10 mm in both diagrams (top and bottom). This means that the scaling is the same.
  • The top axis y line is on the right. Otherwise the 10 and 50 would have been overlapping.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .