2

I'm trying to change the default BarLegend ticks style using the officially documented methods, but nothing changes. I've tried the Method method (Method -> {FrameStyle -> Directive[Thick, Black], FrameTicksStyle -> Directive[Black, 12]}) as it was suggested here (Changing BarLegend border style), but again nothing happened. How can I solve this problem?

The function I'm trying to plot is:

 DensityPlot[func[a,b], {a, 0, 7}, {b, -0.5, 0},
 ColorFunction -> "SunsetColors", ImageSize -> 1080, Frame -> True,
 FrameTicks -> Automatic, FrameStyle -> Directive[Thick, 20, Black],
 FrameLabel -> {Style[a, 25, Black], Style[b, 25, Black]}, PlotPoints -> 50,
 PlotLegends ->
  BarLegend[Automatic,
   Method -> {FrameStyle -> Directive[Thick, Black],
     FrameTicksStyle -> Directive[Orange, 12]}]]

This code returns the following figure.

Result

As you can see, FrameStyle -> Directive[Thick, 20, Black] perfectly works for main plot, but it does nothing with colorbar.

So I'd like to have similar frame ticks and values formatting for the main frame and for colorbar.

Peter Mortensen
  • 759
  • 4
  • 7
DarktIOff
  • 23
  • 6
  • Can you be clearer about what you're trying to achieve, and can you include the code for a minimum working example that displays the issue you're having? – Carl Lange Dec 25 '21 at 20:56
  • I've just tried to do my best with this update @CarlLange – DarktIOff Dec 25 '21 at 21:13
  • Yes, that's loads better, thank you! – Carl Lange Dec 25 '21 at 21:17
  • Does PlotLegends -> BarLegend[Automatic, FrameStyle -> Directive[Thick, Black], LabelStyle -> Directive[Thick, 20, Black]] work for you? – Carl Lange Dec 25 '21 at 21:21
  • Ah, in fact you can pass TicksStyle as well in a Method option: PlotLegends -> BarLegend[Automatic, FrameStyle -> Directive[Thick, Black], Method -> {TicksStyle -> Directive[Thick, Black]}, LabelStyle -> Directive[Thick, 20, Black]] – Carl Lange Dec 25 '21 at 21:25
  • Without Method there's an error (at least my Mathematica 13.0.0 paints in red FrameStyle ). With Method it doesn't work. – DarktIOff Dec 25 '21 at 21:25
  • FrameStyle should still work, even though the syntax checker doesn't believe you (it does for me on 13.0) - although you can pass it in the Method as well. – Carl Lange Dec 25 '21 at 21:26
  • @CarlLange can you please post your comment as an answer to this question? I'd like to mark it as the correct solution for this problem – DarktIOff Dec 25 '21 at 21:27

1 Answers1

6

You can use a combination of LabelStyle and the Method hack in the linked question to get a consistent style for the BarLegend:

DensityPlot[func[a, b], {a, 0, 7}, {b, -0.5, 0}, 
 ColorFunction -> "SunsetColors", ImageSize -> 1080/2, Frame -> True, 
 FrameTicks -> Automatic, FrameStyle -> Directive[Thick, 20, Black], 
 FrameLabel -> {Style[a, 25, Black], Style[b, 25, Black]}, 
 PlotPoints -> 50, 
 PlotLegends -> 
  BarLegend[Automatic, LabelStyle -> Directive[Thick, 20, Black], 
   Method -> {TicksStyle -> Directive[Thick, Black], 
     FrameStyle -> Directive[Thick, Black]}]]

It turns out the BarLegend uses Ticks for the ticks, rather than FrameTicks. I'm not completely sure if that's a new change!

enter image description here

Carl Lange
  • 13,065
  • 1
  • 36
  • 70