6

I use this code

{P1 = RegionPlot[0 <= Cos[y x] <= 1/2, {y, 0, 3}, {x, 0, 5}, 
   PlotStyle -> LightBlue, 
   FrameLabel -> {{Style[Rotate["F", 270 Degree], 15], 
      None}, {Style["y", 15], None}}, BaseStyle -> 15],

P2 = RegionPlot[0 <= Cos[-y x] <= 1/2, {y, 0, 3}, {x, 0, -5}, PlotStyle -> LightBlue, FrameLabel -> {{Style[Rotate["G", 270 Degree], 15], None}, {Style["y", 15], None}}, BaseStyle -> 15]}

and the result is

enter image description here

How can I ask Mathematica to attach the two plots vertically as follows

enter image description here

charmin
  • 1,159
  • 3
  • 7

2 Answers2

6
$Version

(* "12.2.0 for Mac OS X x86 (64-bit) (December 12, 2020)" *)

Clear["Global`"]

Column[{
  P1 = RegionPlot[0 <= Cos[y x] <= 1/2, {y, 0, 3}, {x, 0, 5},
    PlotStyle -> LightBlue,
    FrameTicks -> {{Automatic, Automatic}, {None, Automatic}},
    FrameLabel -> {{Style[Rotate["F", 270 Degree], 15], None}, {None, None}},
    BaseStyle -> 15,
    ImageSize -> 360,
    ImagePadding -> {{40, 5}, {0, 10}}],
  P2 = RegionPlot[0 <= Cos[-y x] <= 1/2, {y, 0, 3}, {x, 0, -5},
    PlotStyle -> LightBlue,
    FrameLabel -> {{Style[Rotate["G", 270 Degree], 15], 
       None}, {Style["y", 15], None}},
    BaseStyle -> 15,
    ImageSize -> 360,
    ImagePadding -> {{40, 5}, {45, 0}}]},
 Spacings -> 0]

enter image description here

Or more simply,

RegionPlot[{0 <= Cos[y x] <= 1/2 && 0 <= x <= 5, 
  0 <= Cos[-y x] <= 1/2 && -5 <= x <= 0}, {y, 0, 3}, {x, -5, 5},
 FrameLabel -> {"y", ""},
 BaseStyle -> 15,
 PlotPoints -> 75,
 PlotLegends -> Placed[{"F", "G"}, Left]]

enter image description here

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
3

I have tried to reproduce the combined plot exactly as you show it in your question. Observe that I managed to make a graphic with just one zero exactly level with the boundary between the two component plots, which is the one tricky thing in this solution

I have also simplified the options wherever I thought it was useful to do so, and I added some new ones that were needed.

Graphics[
  {Text[Style[0, 15], {-.8, .15}],
   Inset[
     GraphicsColumn[
       {RegionPlot[0 <= Cos[y x] <= 1/2, {y, 0, 3}, {x, 0, 5},
          PlotRange -> {Automatic, {0, 5}},
          PlotStyle -> LightBlue,
          FrameTicks -> {{ Range[5], None}, {None, Automatic}},
          FrameLabel -> {None, "F"},
          RotateLabel -> False,
          BaseStyle -> 15,
          ImagePadding -> {{Automatic, Automatic}, {None, Automatic}}],
        RegionPlot[0 <= Cos[-y x] <= 1/2, {y, 0, 3}, {x, -5, 0},
          PlotRange -> {Automatic, {-5, 0}},
          PlotStyle -> LightBlue,
          FrameTicks -> {{ -1 Range[5], None}, {Automatic, None}},
          FrameLabel -> {"y", "G"},,
          RotateLabel -> False,
          BaseStyle -> 15,
          ImagePadding -> {{Automatic, Automatic}, {Automatic, None}}]},
       Spacings -> 0],
     {-1, 2}, {-1, 1}, {2, 4}]},
  PlotRange -> {{-1, 1}, {-2, 2}},
  AspectRatio -> 1.8,
  ImageSize -> 400]

plot

Update

I am not deleting my original solution because I think it still might be of some interest, but I am adding this much simpler solution, which combines Show with Labeled.

Labeled[
  Show[
    RegionPlot[0 <= Cos[y x] <= 1/2, {y, 0, 3}, {x, 0, 5},
      PlotStyle -> LightBlue]],
    RegionPlot[0 <= Cos[-y x] <= 1/2, {y, 0, 3}, {x, -5, 0}],
      PlotStyle -> LightBlue],
    Epilog -> {Line[{{0, 0}, {3, 0}}]},
    BaseStyle -> 15,
    PlotStyle -> LightBlue,
    PlotRange -> All,
    FrameTicks -> {{Range[-5, 5], None}, {Automatic, None}},
    AspectRatio -> 1.8,
    ImageSize -> 400],
  {Column[{"F", Splice @ ConstantArray["\n", 18], "G", "\n"}], "y"},
  {Left, Bottom},
  LabelStyle -> 15]

plot

m_goldberg
  • 107,779
  • 16
  • 103
  • 257