Beberapa plot matriks dengan bilah warna yang sama, tetapi tidak dapat membedakan nilainya
Saya perlu membuat grup MatrixPlots dengan bilah warna yang sama. Matriks memiliki nilai pada skala yang berbeda. Di sini saya telah menulis kode di mana matriks dibuat dengan RandomReal
fungsi.
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"]]

Saya telah mengikuti solusi dari pertanyaan tentang colorbar umum . Tetapi di sini tidak mungkin menggunakan bilah warna umum untuk mengetahui tentang nilai besar atau kecil dari t semua plot matriks yang berbeda. Semua plot matriks berdiri sendiri. Saya tidak dapat menggabungkan matriks karena, saya perlu menyebutkan frameticks ke semua plot. Bisakah seseorang membantu mengatasi masalah ini?
Jawaban
SeedRandom[1]
{mat1, mat2, mat3, mat4} = RandomReal[{-#, #}, {3, 3}] & /@ {100, 50, 5, .1};
minmax = MinMax@{mat1, mat2, mat3, mat4};
1. Gunakan ColorFunction -> ColorData[{"Rainbow", minmax}]
dan tambahkan opsi 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. Ubah skala matriks input dan tambahkan opsi 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. Anda juga dapat menggunakan matriks warna (diperoleh dengan memetakan ColorData['Rainbow"]
pada matriks masukan yang diskalakan ulang) sebagai argumen pertama dalam 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}]]

Masalahnya adalah bahwa Mathematica secara otomatis menskalakan semua nilai matriks agar berada dalam rentang {0, 1}
sebelum meneruskannya ColorFunction
.
Solusinya adalah dengan menentukan milik Anda sendiri ColorFunction
yang melakukan penskalaan untuk Anda. Ini juga berarti Anda perlu mengatur ColorFunctionScaling -> False
. Misalnya
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"]]
