0

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.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
seeker
  • 539
  • 2
  • 7

1 Answers1

1
$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

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
  • 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? – seeker Jul 27 '22 at 12:46
  • 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. – Bob Hanlon Jul 27 '22 at 15:55