3
$\begingroup$

I want to make a color bar with nonlinear scale , with code

DensityPlot[v, {u, 0, 1}, {v, 1, 5}, ColorFunctionScaling -> False, ColorFunction -> (Blend[{{1, Red}, {2, Green}, {3, Blue}, {4, Yellow}, {5, Orange}}, #] &), AspectRatio -> 10, Frame -> True, PlotRangePadding -> 0, ImagePadding -> 25, FrameTicks -> {None, Automatic}, FrameLabel -> None]

I get the result

enter image description here

How to replace 1, 2, 3, 4, 5 labels with other labels e.g. 3, 9, 27, 81, 243?

$\endgroup$
  • $\begingroup$ Have you tried Ticks option? $\endgroup$ – Gae P Apr 26 at 11:50
4
$\begingroup$

Manual FrameTicks solution

In your specific example an easy way you can get the desired result by specifying the FrameTicks manually like this:

FrameTicks -> {{{{1, 3}, {2, 9}, {3, 27}, {4, 81}, {5, 243}}, None}, {None, None}}

New FrameTicks

ScalingFunction with automatic FrameTicks solution

If the coordinate value to screen mapping you want to show itself is not linear, starting with V12 you can also use ScalingFunction in most plot functions. In your example you could e.g. do it like this:

DensityPlot[v, {u, 0, 1}, {v, 3, 243},
  ColorFunctionScaling -> False, 
  ColorFunction -> (Blend[{{1, Red}, {2, Green}, {3, Blue}, {4, Yellow}, {5, Orange}}, Log[3, #]] &),
  AspectRatio -> 10, Frame -> True, PlotRangePadding -> 0, ImagePadding -> 25, FrameLabel -> None,
  ScalingFunctions -> {None, {Log[3, #] &, 3^# &}},
  FrameTicks -> {{Automatic, None}, {None, None}}
]

Automatic FrameTicks and ScalingFunction

Notice that we didn't have to manually specify the FrameTicks, they were generated for us, and that the ColorFunction now needs to be nonlinear, too.

$\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.