3
$\begingroup$

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[
    Transpose[ReadList["DOS_E=-2.5_2.5_rL=0_rR=0.1_eta=0.01_L=10.txt",Number,RecordLists->True]],
    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}
]

Density of states as a function of quasiparticle energy and position in the wire

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?

$\endgroup$
4
$\begingroup$

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]

sample img

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]

img2

$\endgroup$
2
  • 1
    $\begingroup$ FYI if you export and upload graphics as PNG rather than JPG you will get much better quality. $\endgroup$ – Simon Woods Jul 17 '16 at 15:27
  • $\begingroup$ Especially the ColorData part is useful, as so much information is lost with the single colours. $\endgroup$ – Betohaku Jul 17 '16 at 16:04
3
$\begingroup$

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
 ]
$\endgroup$
0
$\begingroup$

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,
  MeshShading -> { Automatic, Red}]

enter image description here

This approach avoids blending of colors at boundaries.

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