1

I have the following code:

Module[{n = 300, p = 0.29}, 
  RegionPlot[{y > (1/2)*(n - x) && y + x <= n && y > p/(1 - p)*x}, 
    {x, 0, n}, {y, n, 0}, FrameLabel -> {"x", "y"}, 
    PlotStyle -> {Directive[Yellow, Opacity[0.5]]}]]

which will give you the yellow region on the LHS in the figure below.

enter image description here

Question: I want to revert the y-axis of the RegionPlot so that the axis will look like the RHS in the figure above and the position and the shape of the region change accordingly. This would be the first step to make a ternary RegionPlot.

wdg
  • 1,189
  • 9
  • 18

1 Answers1

7

1. If you need to change just the tick labels you can use FrameTicks as follows:

rp1 = Module[{n = 300, p = 0.29}, 
   RegionPlot[{y > (1/2)*(n - x) && y + x <= n && y > p/(1 - p)*x}, {x, 0, n}, {y, n, 0},
    FrameLabel -> {"x", "y"},  PlotStyle -> {Directive[Yellow, Opacity[0.5]]}, 
    FrameTicks -> {{{#, ToString[300 - #]} & /@ Range[0, 300, 50], None}, {All, None}}]]

enter image description here

2. If you need to change the region polygon too, you can simply change all ys to (n-y) in the first argument of RegionPlot:

 rp2 = Module[{n = 300, p = 0.29}, 
    RegionPlot[{(n - y) > (1/2)*(n - x) && (n - y) + x <= n && (n - y) >
      p/(1 - p)*x}, {x, 0, n}, {y, n, 0}, FrameLabel -> {"x", "y"}, 
   PlotStyle -> {Directive[Yellow, Opacity[0.5]]}, 
   FrameTicks -> {{{#, ToString[300 - #]} & /@ Range[0, 300, 50], None}, {All, None}}]]

enter image description here

3. Post-processing the graphics primitives using GeometricTransformation[_,AffineTransform[_]] and the options using ReplaceAll:

rp = Module[{n = 300, p = 0.29},
RegionPlot[{y > (1/2)*(n - x) && y + x <= n && y > p/(1 - p)*x}, {x, 0, n}, {y, n, 0},
    FrameLabel -> {"x", "y"},  PlotStyle -> {Directive[Yellow, Opacity[0.5]]},
    ImageSize -> 350]];
rpb = MapAt[GeometricTransformation[#, AffineTransform[{{{1, 0},{0, -1}},{0, 300}}]] &,
            rp, {1}];
ticks = MapAt[# /.{a_, b_Real, {c_, 0.}, d___} :>{a, Round[300. - b, 1], {c, 0.}, d} &, 
        AbsoluteOptions[rpb, FrameTicks], {{1, 2, 2}}];
Row[{rp, rpb, 
 Show[rpb, ticks, ImagePadding-> {{Automatic, Automatic}, {Automatic, 0}}]},Spacer[5]]

enter image description here

4. ... use this function to get the final output:

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896