13

I want all the lines in my plot to be a consistent style, let's say thick and black for the purpose of this question.

ContourPlot[y - x^2, {x, 0, 1}, {y, 0, 1},
 ContourStyle -> Directive[Thick, Black, Opacity[1]], 
 FrameStyle -> Directive[Thick, Black],
 PlotLegends -> BarLegend[Automatic]]

enter image description here

However, the border of the legend bar is thin and grey. How do I change its style to match? I couldn't find any relevant options in the BarLegend documentation.

  • 1
    I'm really glad you asked this. I needed this in the past but I never had the time and persistence to solve it. The problem is that if I really need it then I usually don't have time to find a good solution. It's a bit paradoxical, but it's sometimes easier to solve other people's problems than our own. – Szabolcs Sep 09 '14 at 03:37

3 Answers3

13

The following works in both v9 and v10:

style = Directive[Thick, Black];

ContourPlot[y - x^2, {x, 0, 1}, {y, 0, 1}, 
 ContourStyle -> Directive[Thick, Black, Opacity[1]], 
 FrameStyle -> style, 
 PlotLegends -> BarLegend[Automatic, Method -> {FrameStyle -> style}]]

The idea to use the (undocumented) Method option comes from inspecting the full form of the expression both in v9 and v10. In v10, it is

Legended[Graphics[...], BarLegend[..., Method -> {(* all sorts of graphics options*)}]]

In v10, the Method part is missing. This is why belisarius's solution works in v9 only but not in v10.

Thanks to belisarius for providing the main hint for this solution!

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
5
ContourPlot[y - x^2, {x, 0, 1}, {y, 0, 1}, 
  ContourStyle -> Directive[Thick, Black, Opacity[1]], 
  FrameStyle -> Directive[Thick, Black], 
  PlotLegends -> BarLegend[Automatic]] /. 
 HoldPattern[PlotRangePadding -> Automatic] :>
  Sequence[FrameStyle -> Thick, PlotRangePadding -> None]

Mathematica graphics

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
3

You can also use "FrameStyle"->Thick in Version 10:

ContourPlot[y - x^2, {x, 0, 1}, {y, 0, 1},
ContourStyle -> Directive[Thick, Black, Opacity[1]],
FrameStyle -> Thick,
PlotLegends ->  BarLegend[Automatic, "FrameStyle" -> Thick]]

enter image description here

In Version 9 (Windows 8 x64) BarLegend[Automatic, "FrameStyle" -> Thick] renders only three sides of the frame thick. Using

BarLegend[Automatic, "FrameStyle" -> Thick,"AxesStyle"->Thick]

gives the desired result.

kglr
  • 394,356
  • 18
  • 477
  • 896