Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to plot a big 2D array of experiment data. I need plot axes and tick labels as well as a bar legend using BarLegend:

ArrayPlot[
 Array[RandomInteger[100] &, {100, 100}],
 PlotLegends -> Placed[Automatic, Below],
 ImageSize -> 200,
 PlotLabel -> "Test",
 FrameLabel -> {"Axes", "Dimensions"},
 FrameTicks -> Automatic,
 BaseStyle -> {FontSize -> 14}
]

The output I get is

output of the test script

I am not happy with the size of the BarLegend. I would like to have the BarLegend with the width and horizontal offset of the actual plot. It properly scales with the image size, if I don't use the PlotLabel, FrameTicks and FrameLabel but I need all of them.

I would be happy also with the solutions, which does work in general case, but needs adjusting some number by hand. So far I have figured out, that I can change the horizontal offset with PlotLegends -> Placed[BarLegend[Automatic, LegendMargins -> {{20, 20}, {0, 0}}], Below], but this does not make the legend smaller.

As the BarLegend does not return Graphics, I can not just use Scale[BarLegend["BlueGreenYellow", LegendMargins -> {{20, 20}, {0, 0}}], 2] etc.

Side note: For plotting experiment data I use ArrayPlot instead of ListContourPlot and similar because they get very slow for big arrays. And at least ListContourPlot suffers from the same problem.

share|improve this question
add comment

1 Answer 1

up vote 6 down vote accepted

As it often happens, when I was researching for writing a fine question I also digged through the documentation and found the answer. There is an option LegendMarkerkSize which in my opinion has an unintuitive name in the case of the BarLegend. Anyway it is exactly meant to do what I needed:

testPlot = ArrayPlot[
  Array[RandomInteger[100] &, {100, 100}],
  PlotLegends -> 
   Placed[BarLegend[Automatic, LegendMarkerSize -> 125, 
     LegendMargins -> {{10, 0}, {0, 0}}], Below],
  ImageSize -> 200,
  PlotLabel -> "Test",
  FrameLabel -> {"Axes", "Dimensions"},
  FrameTicks -> Automatic,
  BaseStyle -> {FontSize -> 14}
  ]

Outcome

enter image description here

As I already wrote the detailed question, I hope it was worth sharing the solution.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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