5
$\begingroup$

How to add label to the colorbar generated using ArrayPlot and PlotLegends

E.g. color represents 'meters'. I would like to add that label next or below the colorbar.

x = {{1, 45, 32, 8, 0, 90, 20, 1}, {0.5, 4, 5, 10, 70, 1, 1, 7}};
ArrayPlot[x, PlotLegends -> {Placed[Automatic, Below]}]
$\endgroup$
6
$\begingroup$

You could do:

x = {{1, 45, 32, 8, 0, 90, 20, 1}, {0.5, 4, 5, 10, 70, 1, 1, 
   7}}; ArrayPlot[x, 
 PlotLegends -> {Placed[
    BarLegend[Automatic, Automatic, LegendLabel -> "metres"], Below]}]

enter image description here

$\endgroup$
5
$\begingroup$

Using the third parameter of Placed is probably the most direct:

x = {{1, 45, 32, 8, 0, 90, 20, 1}, {0.5, 4, 5, 10, 70, 1, 1, 7}};

ArrayPlot[x, PlotLegends -> Placed[Automatic, Below, Labeled[#, "meters"] &]]

enter image description here

The third parameter of Labeled can be used to set the placement of the label, e.g. Placed[Automatic, Below, Labeled[#, "meters", Right] &]. For left or right placement this alternative also works:

ArrayPlot[x, PlotLegends -> {Placed[Automatic, Below], Placed["meters", Below]}]

enter image description here

ArrayPlot[x, PlotLegends -> {Placed["meters", Below], Placed[Automatic, Below]}]

enter image description here

$\endgroup$
3
  • $\begingroup$ I am always missing the natural answer...not sure I will ever learn :( p.s. nice illustration of North America v terra Australis spelling $\endgroup$
    – ubpdqn
    Aug 5 '16 at 11:59
  • $\begingroup$ @ubpdqn Please do not be disheartened like that. Your answer is very good and opens to door to more extensive customization. I already voted for it, as I have for many other answers of yours. $\endgroup$
    – Mr.Wizard
    Aug 5 '16 at 12:01
  • $\begingroup$ @ubpdqn See, the OP like your answer better. :-) $\endgroup$
    – Mr.Wizard
    Aug 9 '16 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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