2
$\begingroup$

Data for plot

mat11 ={{1.247`,1.2508`,1.26`,1.2769`},{1.1497`,1.1518`,1.1584`,1.1704`},{0.914`,0.915`,0.917`,0.92`},{0.789`,0.789`,0.79`,0.791`}}
mat12={{1.7227`,1.7352`,1.7792`,1.8996`},{1.4969`,1.502`,1.5181`,1.5485`},{1.0731`,1.0737`,1.0755`,1.0785`},{0.908`,0.909`,0.909`,0.911`}}
mat13 ={{1.8568`,1.8731`,1.9332`,2.1544`},{1.5623`,1.5671`,1.5818`,1.6082`},{1.0954`,1.0958`,1.0973`,1.0997`},{0.925`,0.925`,0.926`,0.927`}}
mat14 ={{1.875`,1.8919`,1.9543`,2.1989`},{1.57`,1.5746`,1.5889`,1.6145`},{1.0979`,1.0984`,1.0998`,1.1021`},{0.927`,0.927`,0.928`,0.929`}}

Plotting code

Table[
  ListPlot3D[MATRIX,
    Mesh -> Automatic,
    MeshStyle -> Directive[GrayLevel[0], Dotted],
    PlotLabel -> 
      Style[
        Framed["Spring const. ratios: Subscript[k, 1] = ??, Subscript[k, 2] = ??"],
        32, Black, Background -> None],
    InterpolationOrder -> 3,
    PlotRange -> {{1, 4}, {1, 4}, {0.75, 2.25}},
    ImageSize -> Large,
    AxesLabel ->
      {Style[μ ,42, Italic, Bold, Red, FontFamily -> "Times"],
       Style[η, 42, Italic, Bold, Blue, FontFamily -> "Times"]}, 
    LabelStyle -> Directive[Medium, Black, FontFamily -> "Times"],
    PlotLegends-> 
      Placed[
        BarLegend[
          Automatic,
          Round[Range[Min @ mat11, Max @ mat14,(Max @ mat14 -Min @ mat11)/5], 0.01],
          LabelStyle -> Directive[Black, FontSize -> 26, Bold]],
        Below],
    ViewPoint -> {-3, -2.9, 2},
    FaceGrids -> {{1, 0, 0}, {0, 1, 0}, {0, 0, -1}},
    FaceGridsStyle -> Directive[Black, Bold, Dashed],
    ColorFunction -> "CMYKColors",
    Ticks -> 
      {{{1,"0"}, {2,"0.2"}, {3,"0.4"}, {4,"0.6"}}, {{1,"0"}, {2,"0.1"}, 
        {3,"0.5"}, {4,"1"}},
       {0.75,1,1.25,1.5,1.75,2,2.25}}, 
    TicksStyle -> Directive[Black, Bold, 26]],
  {MATRIX, {mat11, mat12, mat13, mat14}}]

How can I make sure that I have the the same range for the barlegend for all four plot ranges in the z-axis (0.75 < z < 2.25)? At the moment, the barlegend range only applies to a particular lists; e.g., mat11 or mat12. I want to have a universal legend such that the range and colour scaling are the same for all four plots.

$\endgroup$
2
$\begingroup$

I think this will give the plot and bar legend coloring you are looking for.

The major medications are

  • using Legended to place the common bar chart
  • revision of the ColorFunction option
  • adding ColorFunctionScaling -> False
  • removing the LabelStyle option (can't use this option if you style labels in the AxesLabel option.

minmax = Round[MinMax @ {mat11, mat12, mat13, mat14}, .01];

Column[
  Table[
    Legended[
      ListPlot3D[MATRIX,
        ColorFunction -> ColorData[{"CMYKColors", minmax}],
        ColorFunctionScaling -> False,
        Mesh -> Automatic,
        MeshStyle -> Directive[GrayLevel[0], Dotted],
        PlotLabel ->
          Framed[
            Style[
              Row[
               {"Spring const. ratios: " , 
                Subscript[k, 1], 
                "= ??, ", 
                Subscript[k, 2] , 
                " = ??"}],
              "TR", Black, Background -> None]],
        InterpolationOrder -> 3, 
        PlotRange -> {{1, 4}, {1, 4}, {0.75, 2.25}},
        ImageSize -> Medium,
        AxesLabel -> 
          {Style[μ, 12, "TBI", Red], Style[η, 12, "TBI", Blue]},
        ViewPoint -> {-3, -2.9, 2},
        FaceGrids -> {{1, 0, 0}, {0, 1, 0}, {0, 0, -1}},
        FaceGridsStyle -> Directive[Black, Bold, Dashed], 
        Ticks -> 
          {{{1, "0"}, {2, "0.2"}, {3, "0.4"}, {4, "0.6"}}, {{1, "0"}, {2, "0.1"}, 
            {3, "0.5"}, {4, "1"}}, 
           {0.75, 1, 1.25, 1.5, 1.75, 2, 2.25}}, 
        TicksStyle -> Directive[Black, Bold]],
      Placed[
        BarLegend[{"CMYKColors", minmax},
          LegendLayout -> "Row",
          LabelStyle -> Directive[Black, 10, Bold]],
        Below]],
    {MATRIX, {mat11, mat12, mat13, mat14}}]]

column

Note: I have made some cosmetic changes so that the results would look good when posted on this site.

$\endgroup$

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.