# How to change the colour of parts of a 3D plot, rather than the whole figure?

By exporting Matlab data to a txt file and importing it with List3DPlot, I plotted the density of states in a nanowire sandwiched between two bulk materials:

SetDirectory[NotebookDirectory[]]
ListPlot3D[
PlotRange->All,
Ticks->{{{50.5,"0"},{30.5,"-1"},{70.5,"1"}},{{25.5,"0"},{125.5,"L"}},Automatic},
AxesLabel->{"\[Epsilon]/\[CapitalDelta]", "x", "DOS"},
ImageSize->750,ViewPoint->{150,-250,250}
]


For completeness, the text file with the data points is available on Dropbox (which should be saved as DOS_E=-2.5_2.5_rL=0_rR=0.1_eta=0.01_L=10.txt in the notebook folder).

The part between 0<x<L is the nanowire, the parts x<0 and x>L are the bulk materials (normal metal on the left, superconductor on the right). In order to clearly show the structure of the sample, the part of the plot that represents the nanowire should have a different colour.

Question: How can the part 0<x<L be coloured with a different colour function than the parts x<0 and x>L?

Actually I think what you need is ColorFunction and ColorFunctionScaling.

In ColorFunction you can set the color in different regions according to the points' {x,y,z} coordination. And I think what you need is just setting some part in a color (in my code, Bed) and the other in another color(in my code, Blue). Then, simply create a function discribing this and set ColorFunctionScaling to False:

Plot3D[Sin[x] Sin[y], {x, -10, 10}, {y, -10, 10},
ColorFunction -> Function[{x, y, z}, If[5 >= x >= 0, Blue, Red]],
ColorFunctionScaling -> False]


A more beautiful image, illustrating that you can add whatever you want in ColorFunction and the usage of ColorData to easily and elegantly represent your data:

Plot3D[Sin[x] Sin[y], {x, -10, 10}, {y, -10, 10},
ColorFunction ->
Function[{x, y, z},
If[5 >= x >= -5, ColorData["BrightBands"][(x + 5)/10],
ColorData["TemperatureMap"][z]]], ColorFunctionScaling -> False]


• FYI if you export and upload graphics as PNG rather than JPG you will get much better quality. Jul 17, 2016 at 15:27
• Especially the ColorData part is useful, as so much information is lost with the single colours. Jul 17, 2016 at 16:04

A recommendation to the question poser: Pose your question in the absolute simplest terms, limiting to the minimal example that addresses your point. There is no need here, for instance, for the community to have to download a complicated data set in order to see how to color one part of a plot differently from others. Why do we need to incorporate text for ticks? Or funny labels?

Here's a basic example:

Plot3D[Sin[x + y], {x, -2, 2}, {y, -2, 2},
ColorFunction -> Function[{x, y}, If[Abs[x]/2 > .5, Red, Blue]],
ColorFunctionScaling -> False
]


You can also use MeshFunctions + Mesh + MeshShading combination:

{k, l} = {0, 5};
Plot3D[Sin[x] Sin[y], {x, -3 Pi, 3 Pi}, {y, -2 Pi, 2 Pi},
MeshFunctions -> {# &},
Mesh -> {{k, l}},
MeshStyle -> None,