13
$\begingroup$

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.

$\endgroup$
1
  • 1
    $\begingroup$ 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. $\endgroup$
    – Szabolcs
    Commented Sep 9, 2014 at 3:37

3 Answers 3

13
$\begingroup$

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!

$\endgroup$
2
  • $\begingroup$ Nice. The Method Option is the joker of the deck. They use it for everything. +1 $\endgroup$ Commented Sep 9, 2014 at 3:25
  • 2
    $\begingroup$ Nice. Actually you can get away with BarLegend[Automatic, Method -> {FrameStyle -> Thick}]. Black frame is default. $\endgroup$
    – m_goldberg
    Commented Sep 9, 2014 at 3:35
5
$\begingroup$
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

$\endgroup$
7
  • 1
    $\begingroup$ I tried this in V10 running on OS X -- didn't work. $\endgroup$
    – m_goldberg
    Commented Sep 9, 2014 at 1:51
  • $\begingroup$ @m_goldberg Hmm.. sorry. I can't test it on v10 :( $\endgroup$ Commented Sep 9, 2014 at 2:01
  • $\begingroup$ Unfortunately, OP is running on V10. I can tell because his contour plot has the V10 default coloring scheme. So he needs a answer that works on V10. $\endgroup$
    – m_goldberg
    Commented Sep 9, 2014 at 2:05
  • $\begingroup$ @m_goldberg Could you paste the FullForm for the plot somewhere for me?. Perhaps I find an easy way out $\endgroup$ Commented Sep 9, 2014 at 2:37
  • $\begingroup$ The full form expression is 162000 characters. Maybe we should go to chat to talk further about this? I'm in our main chat room now. $\endgroup$
    – m_goldberg
    Commented Sep 9, 2014 at 2:55
3
$\begingroup$

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.

$\endgroup$

Your Answer

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