1
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ See, e.g., here and related/linked posts, and do a search for "reverse axis"... $\endgroup$
    – ciao
    Apr 21, 2014 at 2:58
  • $\begingroup$ @rasher, I saw that post too. However, DataReversed is not even a keyword in RegionPlot. $\endgroup$
    – wdg
    Apr 22, 2014 at 9:59

1 Answer 1

7
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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