2
$\begingroup$

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.

$\endgroup$
8
  • $\begingroup$ 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? $\endgroup$
    – Carl Lange
    Dec 25, 2021 at 20:56
  • $\begingroup$ I've just tried to do my best with this update @CarlLange $\endgroup$
    – DarktIOff
    Dec 25, 2021 at 21:13
  • $\begingroup$ Yes, that's loads better, thank you! $\endgroup$
    – Carl Lange
    Dec 25, 2021 at 21:17
  • $\begingroup$ Does PlotLegends -> BarLegend[Automatic, FrameStyle -> Directive[Thick, Black], LabelStyle -> Directive[Thick, 20, Black]] work for you? $\endgroup$
    – Carl Lange
    Dec 25, 2021 at 21:21
  • $\begingroup$ 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]] $\endgroup$
    – Carl Lange
    Dec 25, 2021 at 21:25

1 Answer 1

6
$\begingroup$

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

$\endgroup$

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.