Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to plot two functions. One should appear on top of the other. The x axis has the same values for both functions, but should appear twice (the second- upper I want to be dashed). y axis should change to dashed type (when it reaches a little more than the highest value for the first function), start from zero again and have a different frame label. Here is just a simple example how can I present the graphs:

Needs["PlotLegends`"]
Plot[{Sin[x], Cos[x]}, {x, 0, 2 \[Pi]}, 
 PlotStyle -> {Red, {Black, Dashed, Thick}}, 
 BaseStyle -> {FontFamily -> "Times", FontSize -> 16}, 
 Frame -> {True, True, False, True}, 
 FrameLabel -> {"x", "y", "", "y1"}, 
 FrameStyle -> {Directive[18], Directive[18], Directive[18], Directive[18, Dashed, Thick]}, 
 PlotLegend -> {Style["Sin(x)", 14], Style["Cos(x)", 14]}, 
 LegendPosition -> {1.05, 0.1}, LegendSize -> {0.4, 0.3}, 
 LegendShadow -> 0.005, LegendTextSpace -> 4, ImageSize -> 550]

But I don't want the functions to be together. Let's say cos(x) in example should be above sin(x) and y1 should start above the end of y (at value y= 1.2). I also want to have another (dashed) x axis, which is at value y=1.2 (y1=0).

enter image description here

EDIT: Thank you for all answers. I tried all of them and come to my final code:

AA = Plot[barvilo, {\[Lambda], 337, 717}, PlotRange -> {0, 1.8}, 
   PlotStyle -> {Black, Dashed, Thick}, 
   BaseStyle -> {FontFamily -> "Times", FontSize -> 16}, 
   Frame -> {True, True, False, False}, ImageSize -> 1200, 
   FrameLabel -> {"", "Absorbanca [p.e.]"}, 
   FrameStyle -> {Directive[18, Dashed], Directive[18, Dashed]}, 
   PlotLegend -> Style["\[Alpha](N719)", 14], 
   LegendPosition -> {1.1, -0.15}, LegendSize -> {0.3, 0.2}, 
   LegendShadow -> 0.005, LegendTextSpace -> 2, 
   ImagePadding -> {{60, 30}, {50, 30}}];
BB = Plot[{a, b, c, d}, {\[Lambda], 337, 717}, PlotRange -> {0, 1.9}, 
   PlotStyle -> {Red, Orange, Black, Purple}, 
   BaseStyle -> {FontFamily -> "Times", FontSize -> 16}, 
   Frame -> {True, True, False, False}, 
   FrameLabel -> {"Valovna dolžina [nm]", 
     "Spektralna gostota sevanja [W/\!\(\*SuperscriptBox[\(m\), \
\(2\)]\)nm]"}, FrameStyle -> {Directive[18], Directive[18]}, 
   Filling -> {1 -> {{4}, {Lighter[Yellow], Opacity[0.02]}}, 
     4 -> {Axis, {Lighter[Yellow], Opacity[0.06]}}}, 
   ImagePadding -> {{60, 30}, {50, 30}}, 
   PlotLegend -> {Style["AM1,5G", 14], Style["AM1,5G + TrPt", 14], 
     Style["AM1,5G + TrEl", 14], Style["AM1,5G + TrPtEl", 14]}, 
   LegendPosition -> {1, 0.1}, LegendSize -> {0.4, 0.3}, 
   LegendShadow -> 0.005, LegendTextSpace -> 4, ImageSize -> 1200];
izracun = 
  Graphics[Text[
    StyleForm["269,37 W/\!\(\*SuperscriptBox[\(m\), \(2\)]\)", 
     FontSize -> 16], {550, -900}, {-1, -1}]];
izracun1 = 
  Graphics[Text[
    StyleForm["490,22 W/\!\(\*SuperscriptBox[\(m\), \(2\)]\)", 
     FontSize -> 16], {160, -970}, {-1, -1}]];
Show[GraphicsColumn[{AA, BB}, 
  Spacings -> {0, -380}], izracun, izracun1]

I am satisfied with it but I need to save it. Why is it not possible to save it, when I select it (Save selection as)? I can save like this just separate graphs (AA and/or BB). When I tried the code in the link bellow, the result is in the right form to save with Save graphic as. But this code is to complicated for me. http://mathematica.stackexchange.com/a/6882/6357

I can use print screen option .. Is there a better way to save it?

share|improve this question
    
What version of Mma are you using? Version 9 includes PlotLegends. Anyway, just plot each plot separately, as in AA = Plot[ blah ...]; BB = Plot[bleh, ...]; Show[AA,BB] –  wolfies Apr 2 '13 at 17:56
1  
I guess it will be better if you show a plot with your desired result format –  belisarius Apr 2 '13 at 18:04
    
@wolfies It's not what I want, belisarius I think I can not add a picture .. –  Luka Apr 2 '13 at 18:06
    
What does "One should appear on top of the other" mean? –  David Carraher Apr 2 '13 at 18:08
    
@Luka Upload the image elsewhere and we shall paste it here –  belisarius Apr 2 '13 at 18:08

3 Answers 3

Similar to the other answers, you need Grid or GraphicsGrid or their Column equivalent. Grid has the advantage of being more flexible, especially around inter-item spacing; GraphicsGrid forces items to be the same width.

Grid[{{Plot[Sin[x], {x, 0, 2 Pi}, AxesStyle -> Dashed, 
    AxesOrigin -> {0, -1}, 
    ImagePadding -> {{20, 20}, {0, 10}}]}, {Plot[Cos[x], {x, 0, 2 Pi},
     AxesOrigin -> {0, -1}, PlotRange -> {-1, 1.2}, 
    FrameLabel -> {{"x"}, {"y", None}}, 
    ImagePadding -> {{20, 20}, {10, 0}}]}}, Spacings -> {0.1, -0.2}]

enter image description here

Notice that the ImagePadding option is set so that the bottom of the top graph and the top of the bottom graph butt up against each other, but I've left space for the tick labels on other sides.

If you are determined to have the labels sitting in the positions you showed in your drawing, then you will need to use Frame as per Jagra's answer. If I used AxesLabel instead, the y-axis label would be above the axis line, which isn't going to be visible for the lower graph.

You will probably also want to change the setting for Ticks on the x-axis of the upper graph.

You might be interested in this question which shows how to construct nice grids of graphs that all butt up against each other, for arbitrary numbers of rows and columns in the grid.

share|improve this answer

I am not sure what funcs you are plotting, but it seems this does the basic idea ...

AA = Plot[Sin[x] + 1/2, {x, 0, Pi}, AxesOrigin -> {0, 0}, AxesLabel -> {"x", "y"}];
BB = Plot[Cos[x] + 1, {x, 0, Pi}, AxesOrigin -> {0, 0}, AxesStyle -> Dashed, PlotStyle -> Red, AxesLabel -> {"x", "y1"}];
GraphicsColumn[{BB, AA}, Spacings -> 0]

You can modify the axis labelling and tick marks as you desire, for each plot separately. You can also set, Spacings to be negative, e.g. Spacings -> -10, which will make the vertical axes merge into each other :)

share|improve this answer

Looking for something like this?

Grid[{{Plot[
    Sin[x], {x, 0, 2 \[Pi]},
    PlotStyle -> Red,
    BaseStyle -> {FontFamily -> "Times", FontSize -> 16},
    Frame -> {True, True, False, True},
    FrameLabel -> {"", "y", "", ""},
    FrameTicks -> {True, True, None, True},
    FrameTicksStyle -> {White, Automatic, Automatic, Automatic},
    FrameStyle -> Directive[18],
    PlotLegend -> {Style["Sin(x)", 14]},
    LegendPosition -> {1.05, 0.1},
    LegendSize -> {0.4, 0.3},
    LegendShadow -> 0.005,
    LegendTextSpace -> 4,
    ImageSize -> 550,
    AspectRatio -> .5]},
  {Plot[
    Cos[x], {x, 0, 2 \[Pi]},
    PlotStyle -> {Black, Dashed, Thick},
    BaseStyle -> {FontFamily -> "Times", FontSize -> 16},
    Frame -> True,
    FrameTicks -> {True, True, None, True},
    FrameLabel -> {"x", "y1", "", ""},
    FrameStyle -> Directive[18],
    PlotLegend -> {Style["Cos(x)", 14]},
    LegendPosition -> {1.05, 0.1},
    LegendSize -> {0.4, 0.3},
    LegendShadow -> 0.005,
    LegendTextSpace -> 4,
    ImageSize -> 550,
    AspectRatio -> .5]}},
 Spacings -> {0, -.70}
 ]

enter image description here

I've used the basic idea of simply stacking two charts in a Grid. Column might work as well, but Grid can give you a bit more flexibility with formatting if you add other things to this solution.

You might also try working with ImagePadding too tighten up the distance between the two plots.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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