Più grafici a matrice con una barra dei colori comune, ma non è possibile distinguere i valori
Devo creare un gruppo di MatrixPlots con una barra dei colori comune. Le matrici hanno il valore a scala diversa. Qui ho scritto il codice in cui vengono create le matrici con RandomReal
funzione.
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"]]

Ho seguito la soluzione della domanda sulla barra dei colori comune . Ma qui non è possibile usare la barra dei colori comune per conoscere valori piccoli o grandi da t tutti i diversi grafici a matrice. Tutti i grafici a matrice stanno da soli. Non posso combinare le matrici perché, devo menzionare i frametick a tutte le trame. Qualcuno può aiutare ad affrontare questo problema?
Risposte
SeedRandom[1]
{mat1, mat2, mat3, mat4} = RandomReal[{-#, #}, {3, 3}] & /@ {100, 50, 5, .1};
minmax = MinMax@{mat1, mat2, mat3, mat4};
1. Usa ColorFunction -> ColorData[{"Rainbow", minmax}]
e aggiungi l'opzione 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. Ridimensionare le matrici di input e aggiungere l'opzione 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. È inoltre possibile utilizzare matrici di colori (ottenute mediante mappatura ColorData['Rainbow"]
su matrici di input ridimensionate) come primo argomento in 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}]]

Il problema è che Mathematica ridimensiona automaticamente tutti i valori delle matrici in modo che si trovino nell'intervallo {0, 1}
prima di passarlo ColorFunction
.
La soluzione è definire il tuo ColorFunction
che esegue il ridimensionamento per te. Ciò significa anche che è necessario impostare ColorFunctionScaling -> False
. Per esempio
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"]]
