9
$\begingroup$

I'm trying to build an 3D AFM image from raw data with Mathematica. So how do I recreate the "AFM hot" color scheme? I've tried "SolarColors" and "RustTones", but they don't quite do the job.

"AFM hot" looks like this (I took this picture from here):

Test function:

f[x_, y_] := 0.1 + (1 - (x - 2)^2) (1 - (y - 2)^2)

AFM Hot

$\endgroup$
12
$\begingroup$

So these gnuplot color maps are a little bit more complicated than can be easily achieved by Blend (although you can do some cool stuff with Blend).

If you look at this page you can see that they specify a particular mapping function for the three different RGB components as a function of the scaling parameter x.

AFMHot uses functions 33, 34, and 35, which correspond to 2 x, 2 x - 0.5, and 2x - 1.0, where x goes from 0 to 1

afmHot = RGBColor[2 #, 2 # - .5, 2 # - 1] &;

Plot3D[0.1 + (1 - (x - 2)^2) (1 - (y - 2)^2), {x, 1, 3}, {y, 1, 3},
 ColorFunction -> Function[{x, y, z}, afmHot[z]] ]
DensityPlot[
 0.1 + (1 - (x - 2)^2) (1 - (y - 2)^2), {x, 1, 3}, {y, 1, 3},
 ColorFunction -> afmHot , PlotLegends -> Automatic]

enter image description here

You can do the rest of the color maps via

traditional = RGBColor[Sqrt[#], #^3, Sin[2 π #]] &;
greenRedViolet = RGBColor[#, Abs[# - .5], #^4] &;
ocean = RGBColor[3 # - 2, Abs[(3 # - 1)/2], #] &;
hot = RGBColor[3 #, 3 # - 1, 3 # - 2] &;
rainbow = RGBColor[Abs[2 # - .5], Sin[π #], Cos[π/2 #]] &;
afmHot = RGBColor[2 #, 2 # - .5, 2 # - 1] &;

LinearGradientImage[#, {300, 100}] & /@ {traditional, greenRedViolet, 
   ocean, hot, rainbow, afmHot} // Column

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ The component functions are (piecewise) linear, so Blend[] can be used here. See my answer. $\endgroup$ – J. M.'s technical difficulties Mar 24 '16 at 13:11
  • $\begingroup$ Right on - but could you do the nonlinear ones, the ones that call on Sqrt and trig functions? Also, what is meant by the notation in component 32? $\endgroup$ – Jason B. Mar 24 '16 at 13:20
  • $\begingroup$ Of course, you can't use Blend[] on those colors. ;) I'm not sure about those semicolons, I've looked through the manual and all I can find was that they're just separators. $\endgroup$ – J. M.'s technical difficulties Mar 24 '16 at 13:49
  • 1
    $\begingroup$ Okay, it's apparently a piecewise function. Try this: f303132[x_] := RGBColor[Clip[25 x/8 - 25/32 , {0, 1}], Clip[2 x - 21/25, {0, 1}], Piecewise[{{4 x, 0 <= x < 1/4}, {1, 1/4 <= x < 21/50}, {46/25 - 2 x, 21/50 <= x < 23/25}, {(25 x - 23)/2, 23/25 <= x <= 1}}]] $\endgroup$ – J. M.'s technical difficulties Mar 24 '16 at 14:06
9
$\begingroup$

The gradient of interest here is actually a Gnuplot color scheme. From here we find that "AFM hot" corresponds to using components 34, 35, and 36 (with suitable clipping). Thus,

afmhot[x_] /; 0 <= x <= 1 :=
RGBColor[Min[2 x, 1], Min[Max[0, 2 x - 1/2], 1], Max[0, 2 x - 1]]

or, using Blend[],

afmhot[x_] /; 0 <= x <= 1 :=
Blend[{Black, RGBColor[1/2, 0, 0], RGBColor[1, 1/2, 0],
       RGBColor[1, 1, 1/2], White}, x]

Test:

LinearGradientImage[afmhot, {300, 30}]

gradient

Plot3D[1/10 + (1 - (x - 2)^2) (1 - (y - 2)^2), {x, 1, 3}, {y, 1, 3},
       ColorFunction -> (afmhot[#3] &)]

see the colors

| improve this answer | |
$\endgroup$
5
$\begingroup$

As Vitaliy pointed out, you can always define your own colour scheme.

clfun = Blend[{Black, Red, Yellow, White}, #] &; (*color scheme*)
Plot3D[0.1 + (1 - (x - 2)^2) (1 - (y - 2)^2), {x, 1, 3}, {y, 1, 3}, 
 ColorFunction -> Function[{x, y, z}, clfun[z]]]

enter image description here

| improve this answer | |
$\endgroup$
4
$\begingroup$

Before Mathematica had all the colour gradients, I used this blend:

RedTempX[x_] := RGBColor[Min[{1, 4x/3}], Max[{0, 2x-1}], Max[{0, 4x-3}]]

Don't forget you can use an exponent to modify how the colours appear. Here I used an exponent of 0.5.

 Plot3D[0.1 + (1 - (x - 2)^2) (1 - (y - 2)^2), {x, 1, 3}, {y, 1, 3},
        ColorFunction -> (RedTempX[#3^0.5] &), Mesh -> 20]

temperature colour gradient

| improve this answer | |
$\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.