# How can I rotate the LegendLabel in MatrixPlot and extract the color scheme to be used in DensityPlot?

    data = Table[
Sin[x] Cos[y] + 0.05 x y, {x, 0, 2 Pi, 0.1}, {y, 0, 2 Pi, 0.1}];
MatrixPlot[data,
PlotLegends ->
Placed[BarLegend[Automatic, LegendMarkerSize -> 100,
LegendLabel ->
Placed[Style[Text["(Text for Label)"], Red, FontSize -> 22],
Top]], Right], AspectRatio -> 2]


I really have to questions:

updated

1. how can I rotate (90 Degree, see fig below) the red LegendLabel to be aligned with BarLegend?
2. I want to extract the color scheme in the MatrixPlot so I can use it in DensityPlot.

• What about putting the legend bar horizontally above the matrix plot, and putting the label horizontally above the bar. To my opinion, it makes more sense esthetically. Commented Sep 9, 2020 at 20:45
• @yarchik, you are right but I have four panels and I want to stack them together and above, and below the plot, I have different labels. Commented Sep 9, 2020 at 21:28
• Maybe this is relevant? mathematica.stackexchange.com/questions/69952/… Commented Sep 9, 2020 at 21:41
• As to 2nd question: mathematica.stackexchange.com/q/104039/1871 Commented Sep 9, 2020 at 21:42
• Just replace Right by Top in my answer! Commented Sep 9, 2020 at 23:17

data = Table[
Sin[x] Cos[y] + 0.05 x y, {x, 0, 2 Pi, 0.1}, {y, 0, 2 Pi, 0.1}];
MatrixPlot[data, AspectRatio -> 2, DataReversed -> True,
PlotLegends ->
BarLegend[Automatic, LegendMarkerSize -> {25, 250},
LegendLabel ->
Placed[Style["(Text for Label)", 22, Red], Top,
Rotate[#, 90 Degree] &]]]


You can use this approach.

Double click legend and copy and paste.

im=(*put image of legend here*)

matrixPlotColor = Module[{colorlist}, colorlist = Join @@ ImageData@im;
Evaluate[Blend[RGBColor @@@ Reverse[colorlist], #] &]];

DensityPlot[Sin[x] Cos[y] + 0.05 x y, {x, 0, 2 Pi}, {y, 0, 2 Pi},
PlotRange -> All, ColorFunction -> matrixPlotColor, ImageSize -> 220,
PlotLegends -> Automatic, AspectRatio -> 2, PlotPoints -> 100]


• thanks for the answer! Commented Sep 9, 2020 at 22:21
• in the last fig. with DensityPlot, why the white color is not at zer in the BarLegend? Commented Sep 9, 2020 at 23:22
• See my edit. We need to reverse color. It works now. Commented Sep 9, 2020 at 23:34