0
$\begingroup$

In the following RegionPlot3D

  f1 = Sin[x y]; f2 = x + y; f3 = x + z;
RegionPlot3D[
 f1 < 1 && f2 < 1 && f3 < 1, {x, 0, 1}, {y, 0, 1}, {z, 0, 1}, 
 PlotPoints -> 35, PlotRange -> All, AxesLabel -> Automatic, 
 PlotLegends -> Automatic]

I want to understand how to highlight (kind of "PlotLegend") the regions f1, f2, f3.

$\endgroup$
2
  • 1
    $\begingroup$ You might be able to adapt the solution here so that the pieces are colored the way you want them. $\endgroup$ Jul 22 at 15:33
  • $\begingroup$ Since f1<=1 always true, maybe you wan to set f1 < 1/8 for example. $\endgroup$
    – cvgmt
    Jul 23 at 0:38

1 Answer 1

1
$\begingroup$
$Version

(* "13.1.0 for Mac OS X x86 (64-bit) (June 16, 2022)" *)

Clear["Global`*"]

f1 = Sin[x y]; f2 = x + y; f3 = x + z;

data1 = Transpose[{
    (Rest@
      Subsets[
       {f1 < 1/8, f2 < 1/2, f3 < 1/2},
       3]),
    Rest@
     Subsets[
      Opacity[0.5, ColorData[97][#]] & /@
       Range[3],
      3]}];

data2 = ReplacePart[#, 1 -> And @@ #[[1]]] & /@ data1;

data = Drop[Riffle[data1, data2], {1, 5, 2}];

Partition[
  Insert[RegionPlot3D[Evaluate@#[[1]],
      {x, 0, 1}, {y, 0, 1}, {z, 0, 1},
      PlotStyle -> #[[2]],
      PlotRange ->
       {{0, 1}, {0, 1}, {0, 1}},
      PlotPoints -> 50,
      MaxRecursion -> 7,
      PlotRange -> All,
      AxesLabel -> Automatic,
      PlotLabel ->
       StringForm["``", #[[1]]]] & /@
    data,
   SpanFromLeft, 4],
  2] // Grid

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks, but there is some problem. When I run, it shows "{Sin[x\ y]<1/8,x+y<1/2} must be a Boolean function" (I am using version 11.3 on Windows 19). Could you write more simply what data1, data2 and data mean? And what Evaluate@#[[1]] stands for? $\endgroup$
    – seeker
    Jul 27 at 12:46
  • $\begingroup$ The error message "{Sin[x\ y]<1/8,x+y<1/2} must be a Boolean function" appears to indicate an extraneous backslash character was inserted. Did you copy and paste from above or retype the input? The RegionPlot3D expression is being mapped onto the list data. The # is an element of the list data. The element of the list is itself a list. #[[1]] is the fist part (element) of that sublist. Evaluate@#[[1]] is equivalent to Evaluate[#[[1]]] If you don't recognize an operator or function, highlight it in Mathematica and press F1 for help. $\endgroup$
    – Bob Hanlon
    Jul 27 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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