2
$\begingroup$

I have bar with log scale:

 BarLegend[{(Blend[{{Log10@1, White}, {Log10@10, Cyan}, {Log10@100, 
   Blue}}, Log10@#] &), {1, 100}}, Ticks -> {1, 10, 100}]

with result

enter image description here.

How to get log-scale on the bar?

$\endgroup$

2 Answers 2

5
$\begingroup$

The difficulty here is that there are two different spaces you are working in and you have to know where each is being used. Specifically, we want the ticks in $\log_{10}$ space, but the labels in linear space. So, we have to specify the labels, too, to make it work correctly, e.g.

logTicks[min_, max_] := {#, 10^#} & /@ FindDivisions[{min, max}, 5]

Unfortunately, Ticks does not accept a function in BarLegend, otherwise I would do this

BarLegend[{"Rainbow", {0, 5}}, Ticks -> logTicks]

Instead, the range needs to be specified

BarLegend[{"Rainbow", {0, 5}}, Ticks -> logTicks[0,5]]

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ I am using Mathematica 12. Doing what you do, ticks appear reads in my code (but the code is working). Why so ? $\endgroup$
    – StarBucK
    Commented Sep 30, 2020 at 15:24
  • 2
    $\begingroup$ @StarBucK if you run Options@BarLegend, you'll notice Ticks is not in the list. The FE at some point (can't remember exactly when) started marking unknown options red, even if they fell into a hidden list. So, treat the red as just a warning. $\endgroup$
    – rcollyer
    Commented Sep 30, 2020 at 17:08
3
$\begingroup$
BarLegend[
 {
  {White, Cyan, Blue},
  {0, Power[10, 6]}
  }
 , Power[10, Range[0, 5]]
 ]

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ Thank but how to get smooth blend, with 1=White, 10=Cyan and 100= Blue? $\endgroup$
    – Nigel1
    Commented May 29, 2018 at 11:54
  • 1
    $\begingroup$ See the answer by rcollyer. $\endgroup$
    – rhermans
    Commented May 30, 2018 at 9:38

Your Answer

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

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