0
$\begingroup$

I have this question that I've been struggling with. I came across many similar questions, but those solutions do not work for me. What I looked at:

Example 1

Example 2

Example 3

I apologize if I missed something and appreciate your help. The question actually consists of two parts.

Part 1

I want to plot a function using ListContourPlot.

data set

alternative link

bulk3ReCAS = Import["/home/molkee/Desktop/ms-alee/data/plane/lih.3re.cas410.6-31gs.zxdat", "Table"];
alee3ReCAS = bulk3ReCAS[[All, {1, 2, 3}]];
density3ReCAS = bulk3reCAS[[All, {1, 2, 4}]];
cntrValue = 0.0005;
dencntr3reCAS = 
ListContourPlot[density3ReCAS, Contours -> {cntrValue}, 
ContourShading -> {White, None}];

minCf = Min[alee3ReCAS[[All, 3]]];
maxCf = Max[alee3ReCAS[[All, 3]]];

aleemap3ReCAS = ListContourPlot[alee3ReCAS,
InterpolationOrder -> 3,
Contours -> 10,
ContourLabels -> Automatic,
AspectRatio -> 1,
ColorFunction -> (ColorData["Rainbow"][
   Rescale[#1, {minCf, maxCf}, {0, 1}]] &),
ColorFunctionScaling -> False,
ClippingStyle -> Automatic,
PlotLegends -> 
Placed[BarLegend[{"Rainbow", {minCf, maxCf}}, 9, 
  LegendMargins -> 10, 
  LabelStyle -> 
   Directive[FontFamily -> "Helvetica", FontSize -> 14], 
  LegendMarkerSize -> 300, LegendMargins -> 0, 
  LegendLayout -> "Row"], Below],
PlotRangePadding -> None,
ImagePadding -> None,
Frame -> False];

I want my color function span the whole range from min to max in my data set.

I tried to achieve this by

ColorFunction -> (ColorData["Rainbow"][
Rescale[#1, {minCf, maxCf}, {0, 1}]] &),
ColorFunctionScaling -> False

but with no success. This is what I am getting on output: output

However, I was expecting something like this (disregard the labels).

enter image description here

What am I doing wrong? How can I also make the colorbar display the full spectrum of colors?

Part 2

How can I use the same code to plot the same function, but in some particular region? Let me explain. Suppose my data set is in [0,1]. I want to see how the data change in [0.5,0.7] so that all values below 0.5 are purple and those above 0.7 are red as far as the rainbow palette is considered.

My question can be best illustrated by the following image, where the same is accomplished when going from [-1:1] to [0:1]:

enter image description here

Again, I tried many things, but didn't succeed.

$\endgroup$
  • 1
    $\begingroup$ You used a storage service with expiration date. That isn't convenient as the data will be unavailable in a few hours and this site relies on freezing all the relevant info "forever", so anyone will be able to answer anytime in the future. Please use Pastebin or similar ones $\endgroup$ – Dr. belisarius Mar 6 '16 at 20:06
  • $\begingroup$ @Dr.belisarius done $\endgroup$ – molkee Mar 6 '16 at 20:40
2
$\begingroup$

Part 1

With the data and code above , I obtain the plot

enter image description here

which is similar to that in the question, but not identical. The corresponding plot with the full range of colors can be obtained from

ListContourPlot[alee3ReCAS, InterpolationOrder -> 3, Contours -> 10, Frame -> False, 
    ColorFunction -> "Rainbow", PlotRange -> All, 
    PlotLegends -> Placed[BarLegend[Automatic, 9, LegendMargins -> 10, 
    LabelStyle -> Directive["Helvetica", 14], LegendMarkerSize -> 300], Below]]

enter image description here

The BarLegend also is meaningful now.

Part 2

To obtain a plot with colors compressed to a narrower range, say {-2,-1}, use

tem = {#[[1]], #[[2]], Clip[#[[3]], {-2, -1}]} & /@ alee3ReCAS;
ListContourPlot[tem, InterpolationOrder -> 3, Contours -> 10, Frame -> False, 
    ColorFunction -> "Rainbow", PlotLegends -> Placed[BarLegend[Automatic, 9, 
    LegendMargins -> 10, LabelStyle -> Directive["Helvetica", 14], 
    LegendMarkerSize -> 300], Below]]

enter image description here

Note that the many closely spaced contours appear as a small black ring near the center of the plot.

Addendum

As requested in a comment below, this same Part 2 result can be obtained with

ListContourPlot[alee3ReCAS, InterpolationOrder -> 3, Contours -> Range[-2, -1, 1/9], 
    PlotRange -> All, Frame -> False, ColorFunctionScaling -> False, 
    ColorFunction -> (ColorData["Rainbow"][2 + Clip[#, {-2, -1}]] &), 
    PlotLegends -> Placed[BarLegend[{Automatic, {-2, -1}}, 9, LegendMargins -> 10, 
    LabelStyle -> Directive["Helvetica", 14], LegendMarkerSize -> 300], Below]]

It is important to remember that, with ColorFunctionScaling -> False, ColorFunction should be scaled manually to range between 0 and 1.

$\endgroup$
  • $\begingroup$ Thank you, @bbgodfrey! I really want to understand how to achieve what you have done in Part 2 using Rescale and ColorFunctionScaling like in the examples above. If you know the answer, can you help? $\endgroup$ – molkee Mar 7 '16 at 16:12
  • $\begingroup$ @molkee Yes, specifying PlotRange is the key issue for Part 1 in that it assures that all values in the list are plotted, after which ColorFunction automatically takes care of the rest. I also have added the second approach that you requested for Part 2. The same could be done for Part 1, but there is no point in doing so. Finally, note that I simplified the BarLegend code a bit. $\endgroup$ – bbgodfrey Mar 8 '16 at 1:51
  • $\begingroup$ thank you for your kind help! I appreciate it. $\endgroup$ – molkee Mar 9 '16 at 1:13

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.