Varias gráficas de matriz con una barra de colores común, pero no pueden distinguir los valores
Necesito crear un grupo de MatrixPlots con una barra de color común. Las matrices tienen el valor a diferente escala. Aquí he escrito el código donde se crean las matrices con RandomReal
función.
mat1=RandomReal[{-100,100}, {3,3}]; mat2=RandomReal[{-50,50}, {3,3}]; mat3=RandomReal[{-5,5}, {3,3}]; mat4=RandomReal[{-0.1, 0.1}, {3, 3}];
plot1 = MatrixPlot[mat1, ColorFunction -> "Rainbow", Frame -> True,FrameTicks -> {{{1, "n=-2"}, {2,"n=-1"}, {3, "n=0"}}, {{1,"m=-2"}, {2, "-1"}, {3, "0"}}},FrameTicksStyle -> Directive[Bold, 20]];
plot2 = MatrixPlot[mat2, ColorFunction -> "Rainbow", Frame -> True,FrameTicks -> {{{1, "n=-2"}, {2,"n=-1"}, {3, "n=0"}}, {{1,"m=-2"}, {2, "-1"}, {3, "0"}}},FrameTicksStyle -> Directive[Bold, 20]];
plot3 = MatrixPlot[mat3, ColorFunction -> "Rainbow", Frame -> True,FrameTicks -> {{{1, "n=-2"}, {2,"n=-1"}, {3, "n=0"}}, {{1,"m=-2"}, {2, "-1"}, {3, "0"}}},FrameTicksStyle -> Directive[Bold, 20]];
plot4 = MatrixPlot[mat4, ColorFunction -> "Rainbow", Frame -> True,FrameTicks -> {{{1, "n=-2"}, {2,"n=-1"}, {3, "n=0"}}, {{1,"m=-2"}, {2, "-1"}, {3, "0"}}},FrameTicksStyle -> Directive[Bold, 20]];
minmax = MinMax@Flatten[{mat1, mat2, mat3, mat4}, 2];
Legended[GraphicsGrid[Partition[{plot1, plot2, plot3, plot4}, 2]], BarLegend[{"Rainbow", minmax}, LegendLayout -> "Column"]]

He seguido la solución de la pregunta sobre la barra de colores común . Pero aquí no es posible usar la barra de colores común para conocer valores grandes o pequeños de todas las diferentes gráficas de matriz. Todas las gráficas de matriz se sostienen por sí mismas. No puedo combinar las matrices ya que necesito mencionar marcos para todos los gráficos. ¿Alguien puede ayudar a solucionar este problema?
Respuestas
SeedRandom[1]
{mat1, mat2, mat3, mat4} = RandomReal[{-#, #}, {3, 3}] & /@ {100, 50, 5, .1};
minmax = MinMax@{mat1, mat2, mat3, mat4};
1. Use ColorFunction -> ColorData[{"Rainbow", minmax}]
y agregue la opción ColorFunctionScaling -> False
:
plotsa = MatrixPlot[#,
ColorFunction -> ColorData[{"Rainbow", minmax}],
ColorFunctionScaling -> False,
Frame -> True,
FrameTicks -> {{{1, "n=-2"}, {2, "n=-1"}, {3, "n=0"}},
{{1, "m=-2"}, {2, "-1"}, {3, "0"}}},
FrameTicksStyle -> Directive[Bold, 20]] & /@
{mat1, mat2, mat3, mat4};
Legended[GraphicsGrid[Partition[plotsa, 2]], BarLegend[{"Rainbow", minmax}]]

2. Cambie la escala de las matrices de entrada y agregue la opción ColorFunctionScaling -> False
:
plotsb = MatrixPlot[#,
ColorFunction -> "Rainbow",
ColorFunctionScaling -> False,
Frame -> True,
FrameTicks -> {{{1, "n=-2"}, {2, "n=-1"}, {3, "n=0"}},
{{1,"m=-2"}, {2, "-1"}, {3, "0"}}},
FrameTicksStyle -> Directive[Bold, 20]] & /@
Rescale[{mat1, mat2, mat3, mat4}];
Legended[GraphicsGrid[Partition[plotsb, 2]], BarLegend[{"Rainbow", minmax}]]

3. También puede utilizar matrices de colores (obtenidas mediante el mapeo ColorData['Rainbow"]
de matrices de entrada reescaladas) como primer argumento en MatrixPlot
:
plotsc = MatrixPlot[#, Frame -> True,
FrameTicks -> {{{1, "n=-2"}, {2, "n=-1"}, {3, "n=0"}},
{{1, "m=-2"}, {2, "-1"}, {3, "0"}}},
FrameTicksStyle -> Directive[Bold, 20]] & /@
Map[ColorData["Rainbow"], Rescale[{mat1, mat2, mat3, mat4}], {-1}];
Legended[GraphicsGrid[Partition[plotsc, 2]], BarLegend[{"Rainbow", minmax}]]

El problema es que Mathematica escala automáticamente todos los valores de las matrices para que se encuentren en el rango {0, 1}
antes de pasarlo ColorFunction
.
La solución es definir el suyo propio ColorFunction
que haga el escalado por usted. Esto también significa que debe configurar ColorFunctionScaling -> False
. Por ejemplo
mat1 = RandomReal[{-100, 100}, {3, 3}]; mat2 =
RandomReal[{-50, 50}, {3, 3}]; mat3 =
RandomReal[{-5, 5}, {3, 3}]; mat4 = RandomReal[{-0.1, 0.1}, {3, 3}];
minmax = MinMax@Flatten[{mat1, mat2, mat3, mat4}, 2];
cf = ColorData["Rainbow"]@Rescale[#, minmax, {0, 1}] &;
plot1 = MatrixPlot[mat1, ColorFunction -> cf, Frame -> True,
FrameTicks -> {{{1, "n=-2"}, {2, "n=-1"}, {3, "n=0"}}, {{1,
"m=-2"}, {2, "-1"}, {3, "0"}}},
FrameTicksStyle -> Directive[Bold, 20],
ColorFunctionScaling -> False];
plot2 = MatrixPlot[mat2, ColorFunction -> cf, Frame -> True,
FrameTicks -> {{{1, "n=-2"}, {2, "n=-1"}, {3, "n=0"}}, {{1,
"m=-2"}, {2, "-1"}, {3, "0"}}},
FrameTicksStyle -> Directive[Bold, 20],
ColorFunctionScaling -> False];
plot3 = MatrixPlot[mat3, ColorFunction -> cf, Frame -> True,
FrameTicks -> {{{1, "n=-2"}, {2, "n=-1"}, {3, "n=0"}}, {{1,
"m=-2"}, {2, "-1"}, {3, "0"}}},
FrameTicksStyle -> Directive[Bold, 20],
ColorFunctionScaling -> False];
plot4 = MatrixPlot[mat4, ColorFunction -> cf, Frame -> True,
FrameTicks -> {{{1, "n=-2"}, {2, "n=-1"}, {3, "n=0"}}, {{1,
"m=-2"}, {2, "-1"}, {3, "0"}}},
FrameTicksStyle -> Directive[Bold, 20],
ColorFunctionScaling -> False];
Legended[GraphicsGrid[Partition[{plot1, plot2, plot3, plot4}, 2]],
BarLegend[{"Rainbow", minmax}, LegendLayout -> "Column"]]
