4
$\begingroup$

I am building a series of images containing of pairs {ListPlot3D, ListContourPlot}. Each pair I build of the same data. Different pairs are built using different lists. Each list consists of triples of numbers obtained from simulations. Here is a simplified example of two such lists: lst1 and lst2:

lst1={{287.53, -3.9056, -0.19509}, {285., 
  0., -0.17008}, {282.53, -3.9056, -0.84621}, {280., 
  0., -0.42635}, {277.53, -3.9056, -0.80788}, {275., 
  0., -0.18374}, {272.53, -3.9056, -0.10512}, {267.53, -3.9056, 
  0.14343}, {262.53, -3.9056, 0.38534}, {260., 0., 
  0.1107}, {257.53, -3.9056, 0.54232}, {255., 0., 
  0.13746}, {252.53, -3.9056, 0.56614}, {250., 0., 
  0.13022}, {247.53, -3.9056, 0.50053}, {242.53, -3.9056, 
  0.36106}, {237.53, -3.9056, 
  0.18492}, {285.07, -7.7452, -0.36367}, {280.07, -7.7452, -0.75501}, \
{275.07, -7.7452, -0.28235}, {270.07, -7.7452, 
  0.1025}, {265.07, -7.7452, 0.61418}, {260.07, -7.7452, 
  0.82878}, {255.07, -7.7452, 0.84073}, {250.07, -7.7452, 
  0.83521}, {245.07, -7.7452, 0.81444}, {240.07, -7.7452, 
  0.71552}, {235.07, -7.7452, 
  0.33018}, {282.63, -11.503, -0.15494}, {252.63, -11.503, 
  0.86051}, {277.63, -11.503, -0.15051}, {267.63, -11.503, 
  0.34193}, {262.63, -11.503, 0.83247}, {257.63, -11.503, 
  0.86175}, {247.63, -11.503, 0.85662}, {242.63, -11.503, 
  0.84701}, {237.63, -11.503, 0.76866}, {232.63, -11.503, 
  0.2499}, {250.2, -15.184, 0.84063}, {255.2, -15.184, 
  0.83932}, {265.2, -15.184, 0.42432}, {260.2, -15.184, 
  0.79231}, {245.2, -15.184, 0.83}, {240.2, -15.184, 
  0.77331}, {235.2, -15.184, 0.40719}, {247.78, -18.804, 
  0.56472}, {252.78, -18.804, 0.57295}, {257.78, -18.804, 
  0.4808}, {262.78, -18.804, 0.25833}, {242.78, -18.804, 
  0.47256}, {237.78, -18.804, 0.27302}, {245.37, -22.389, 
  0.14368}, {250.37, -22.389, 0.15969}, {255.37, -22.389, 
  0.14369}, {240.37, -22.389, 0.10195}, {220, -50, 0}, {220, 10, 
  0}, {320, -50, 0}, {320, 10, 0}};
lst2={{267.53, -3.9056, 0.32279}, {265., 0., 0.41982}, {262.53, -3.9056, 
  0.97029}, {260., 0., 0.55105}, {257.53, -3.9056, 0.90719}, {255., 
  0., 0.48734}, {252.53, -3.9056, 0.85783}, {250., 0., 
  0.42566}, {247.53, -3.9056, 0.82699}, {245., 0., 
  0.3624}, {242.53, -3.9056, 0.79129}, {240., 0., 
  0.28208}, {237.53, -3.9056, 0.72998}, {235., 0., 
  0.20119}, {232.53, -3.9056, 0.62991}, {230., 0., 
  0.13931}, {227.53, -3.9056, 0.47639}, {222.53, -3.9056, 
  0.2602}, {265.07, -7.7452, 0.54352}, {260.07, -7.7452, 
  0.92105}, {255.07, -7.7452, 0.90585}, {250.07, -7.7452, 
  0.88392}, {245.07, -7.7452, 0.86983}, {240.07, -7.7452, 
  0.85978}, {235.07, -7.7452, 0.85016}, {230.07, -7.7452, 
  0.83593}, {225.07, -7.7452, 0.78334}, {220.07, -7.7452, 
  0.45244}, {215.07, -7.7452, 0.10059}, {252.63, -11.503, 
  0.88882}, {262.63, -11.503, 0.43944}, {257.63, -11.503, 
  0.8587}, {247.63, -11.503, 0.88136}, {242.63, -11.503, 
  0.87289}, {237.63, -11.503, 0.86646}, {232.63, -11.503, 
  0.86135}, {227.63, -11.503, 0.85407}, {222.63, -11.503, 
  0.81219}, {217.63, -11.503, 0.34098}, {250.2, -15.184, 
  0.83259}, {255.2, -15.184, 0.65516}, {260.2, -15.184, 
  0.25372}, {245.2, -15.184, 0.85702}, {240.2, -15.184, 
  0.85679}, {235.2, -15.184, 0.85168}, {230.2, -15.184, 
  0.84164}, {225.2, -15.184, 0.80317}, {220.2, -15.184, 
  0.50421}, {215.2, -15.184, 0.11297}, {247.78, -18.804, 
  0.50219}, {252.78, -18.804, 0.29417}, {257.78, -18.804, 
  0.11532}, {242.78, -18.804, 0.61955}, {237.78, -18.804, 
  0.65236}, {232.78, -18.804, 0.62987}, {227.78, -18.804, 
  0.53777}, {222.78, -18.804, 0.32861}, {217.78, -18.804, 
  0.11236}, {245.37, -22.389, 0.14836}, {240.37, -22.389, 
  0.186}, {235.37, -22.389, 0.19383}, {230.37, -22.389, 
  0.17065}, {225.37, -22.389, 0.12114}, {200, -50, 0}, {200, 10, 
  0}, {300, -50, 0}, {300, 10, 0}};

Now I need to draw both of them. The first yields:

cm = 72/2.54;    
Row[{ListPlot3D[lst1, ColorFunction -> "Rainbow", 
       PlotRange -> {{220, 320}, {-50, 10}, {-1, 1}}, 
       AxesLabel -> {x, y, u}, InterpolationOrder -> 5, 
       ImageSize -> {14*cm, Automatic}, PlotStyle -> Opacity[0.8]],
      ListContourPlot[lst1, PlotRange -> {{220, 320}, {-50, 10}, {-1, 1}},
        InterpolationOrder -> 5, ColorFunction -> "Rainbow", 
       AxesLabel -> {x, y}, ImageSize -> {10*cm, Automatic}]
      }]

enter image description here

The second one returns, however, the following:

Row[{ListPlot3D[lst2, ColorFunction -> "Rainbow", 
   PlotRange -> {{200, 300}, {-50, 10}, {-1, 1}}, 
   AxesLabel -> {x, y, u}, InterpolationOrder -> 5, 
   ImageSize -> {14*cm, Automatic}, PlotStyle -> Opacity[0.8]],
  ListContourPlot[lst2, PlotRange -> {{200, 300}, {-50, 10}, {-1, 1}},
    InterpolationOrder -> 5, ColorFunction -> "Rainbow", 
   AxesLabel -> {x, y}, ImageSize -> {10*cm, Automatic}]
  }]

enter image description here

One can see that the plot range in the vertical direction is identical in both images: from -1 to 1. However, the zero plane is green in one case and dark blue or violet in the other.

Further, I have several such lists. The z-coordinate varies between -1 and +1, or between -0.3 and +1, or -1 and 0.1 or between 0 and 1. It never becomes smaller than -1 or larger than 1. However, each of these plots exhibits its own color.

My question: How to standardize the coloring of the images? I need

  1. that colors of the ListPlot3D more or less (the closer - the better) correspond to that of ListContourPlot

and

  1. That coloring of all pairs {ListPlot3D, ListContourPlot} built with various lists correspond to one another.

Any idea?

$\endgroup$
2
  • 2
    $\begingroup$ Including the legends will make it clear why the colors are different. Or look at MinMax[#[[All, 3]]] & /@ {lst1, lst2} In the first case zero is the middle of the range, and for the second, zero is the bottom of the range. If you want the colors to represent the same values, scale the ColorFunction for all of the lists to the same range, e.g., {-1, 1}. $\endgroup$
    – Bob Hanlon
    Jun 30, 2023 at 15:35
  • 1
    $\begingroup$ @Bob Hanlon, I understand the ranges and why the images are colored like that. I want to enable the reader who looks at the images (with different ranges) to compare them. For that, it would be good if the plane z=0 will be colored LightGreen, for example, +1 would be red, and -1 would be violet. The question is how to achieve that. $\endgroup$ Jun 30, 2023 at 16:00

3 Answers 3

5
$\begingroup$

Using your lists, you can use ColorFunctionScaling -> False to pass the actual function values to your color function, and they write your own custom color function e.g. with Blend:

cm = 72/2.54;

(* This color function assumes that the data ranges from -1 to +1 *)
cf = Blend[{Purple, LightGreen, Red}, (# + 1)/2] &;

(* A helper function containing the plotting code to avoid repetition *)
plotfun = 
  Row[{
    ListPlot3D[#, 
      ColorFunctionScaling -> False, ColorFunction -> (cf[#3] &), 
      PlotRange -> {#2, {-50, 10}, {-1, 1}}, AxesLabel -> {x, y, u}, 
      ImageSize -> {14*cm, Automatic}, PlotStyle -> Opacity[0.8]
    ], 
    ListContourPlot[#, 
      ColorFunctionScaling -> False, ColorFunction -> (cf[#1] &), 
      PlotRange -> {#2, {-50, 10}, {-1, 1}}, AxesLabel -> {x, y}, 
      ImageSize -> {10*cm, Automatic}
    ]
  }]&

(* Plotting data and passing the appropriate plot ranges for each pair of plots *)
MapThread[plotfun, {{lst1, lst2}, {{220, 320}, {200, 300}}}]

enter image description here

$\endgroup$
3
  • $\begingroup$ Thank you. Though all answers answer my question, your approach enabled me to make most vivid image with the ColorFunction: cf = Blend[{Purple, Blue, Cyan, Green, Yellow, Orange, Red}, (# + 1)/2] &;. $\endgroup$ Jul 1, 2023 at 10:00
  • $\begingroup$ @Alexei I'm glad I could help. Thank you for the accept as well. $\endgroup$
    – MarcoB
    Jul 1, 2023 at 10:45
  • $\begingroup$ Dear Marco, I am using your idea for my work and faced one difficulty. The legends that I inlude: PlotLegends -> Placed[BarLegend[Automatic, None, "Ticks" -> {-0.8, 0, 0.8}, "TicksStyle" -> {Black, 12, Italic, FontFamily -> "Times"}, LegendMarkerSize -> 210, LegendLabel -> Style["u", 18, Italic, Black, FontFamily -> "Times"]], Above] is a bit asymmetric. Namely, if I want to show such ticks as -1,0 and 1 I only receive 0 and 1 though the settings of the plot are symmetric. Have you an idea,why could it be? $\endgroup$ Jul 4, 2023 at 13:46
6
$\begingroup$

If you want the colors to represent the same values, scale the ColorFunction for all of the lists to the same range, e.g., {-1, 1}.

cm = 72/2.54;
{zmin, zmax} = {-1, 1};
Legended[
 Grid[{
     ListPlot3D[#,
      ColorFunction ->
       Function[{x, y, z}, ColorData["Rainbow"][(z - zmin)/(zmax - zmin)]],
      ColorFunctionScaling -> False,
      PlotRange -> {{220, 320}, {-50, 10}, {-1, 1}},
      AxesLabel -> {x, y, u},
      InterpolationOrder -> 5,
      ImageSize -> {14*cm, Automatic},
      PlotStyle -> Opacity[0.8]],
     ListContourPlot[#,
      PlotRange -> {{220, 320}, {-50, 10}, {-1, 1}},
      InterpolationOrder -> 5,
      ColorFunction ->
       (ColorData["Rainbow"][(# - zmin)/(zmax - zmin)] &),
      ColorFunctionScaling -> False,
      AxesLabel -> {x, y},
      ImageSize -> {10*cm, Automatic}]} & /@ {lst1, lst2}],
 BarLegend[{"Rainbow", {-1, 1}},
  LegendMarkerSize -> 600]]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you. I've got it. $\endgroup$ Jul 1, 2023 at 9:58
4
$\begingroup$
barLegend = BarLegend[{"Rainbow", {-1, 1}}, 
    LegendMarkerSize -> {1 cm, 300}, "Ticks" -> Join[{-1}, #, {1}], 
    "StyledContours" -> Thread[{#, White}]] &;

Column[Map[Legended[
 Row[ReplaceAll[{{f -> ListPlot3D, a -> 4, af -> AxesLabel -> {x, y, u}}, 
     {f -> ListContourPlot, a -> 0, af -> FrameLabel -> {x, y}}}] @
  f[#, ColorFunction -> ColorData[{"Rainbow", {-1, 1}}], 
    ColorFunctionScaling -> False, 
    PlotRange -> {{200,300} + (# /.{lst1 -> 20, lst2 -> 0}), {-50, 10},{-1, 1}},
    af, InterpolationOrder -> 5, 
    ImageSize -> {(10 + a)*cm, Automatic}]], 
  barLegend[MinMax@#[[All, -1]]]] &] @ {lst1, lst2}]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you. That's fine. $\endgroup$ Jul 1, 2023 at 10:01

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.