0
$\begingroup$
    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.

enter image description here

$\endgroup$
5
  • $\begingroup$ 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. $\endgroup$
    – yarchik
    Sep 9, 2020 at 20:45
  • $\begingroup$ @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. $\endgroup$
    – MMA13
    Sep 9, 2020 at 21:28
  • $\begingroup$ Maybe this is relevant? mathematica.stackexchange.com/questions/69952/… $\endgroup$
    – yarchik
    Sep 9, 2020 at 21:41
  • $\begingroup$ As to 2nd question: mathematica.stackexchange.com/q/104039/1871 $\endgroup$
    – xzczd
    Sep 9, 2020 at 21:42
  • 1
    $\begingroup$ Just replace Right by Top in my answer! $\endgroup$ Sep 9, 2020 at 23:17

1 Answer 1

2
$\begingroup$
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] &]]]

enter image description here


You can use this approach.

enter image description here

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]

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.