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)

               axis x line=top, 
               axis y discontinuity=parallel,
\addplot {x*0};     
\addplot {x^2+50};         

               axis x line=bottom,
\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?

  • 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


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



% override style for non-boxed plots
    % which is the case for both sub-plots
    every non boxed x axis/.style={} 
        group style={
            group name=my fancy plots,
            group size=1 by 2,
            xticklabels at=edge bottom,
            vertical sep=0pt
        scale only axis = true,
        % top diagram           
                        axis x line=top, 
                        axis y discontinuity=parallel,
                        axis y line=right,
        % red line
        \addplot+[red,no markers,line width=2pt]{x^2+50};  
        % bottom diagram           
                        axis x line=bottom,
        % blue line                    
        \addplot+[blue,no markers,line width=2pt]{x*0};           



enter image description here


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

enter image description here


  • 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 .