0
$\begingroup$

I have some data that takes the shape {{x,y,z}...} = somedata. I also have a custom gradient which I made using Blend[{{0.4, RGBColor[1,1,1], {0.3, RGBColor[1,0.9, 0.6]}, {0.3,RGBColor[0,0.7,0.9]}}]

I am trying to do the following,

ListPlot3D[data4, ColorFunction ->Blend[{{0.4, RGBColor[1,1,1], {0.3, RGBColor[1,0.9, 0.6]}, {0.3,RGBColor[0,0.7,0.9]}}], PlotLegends-> True, PlotRange -> {0,1}]

z-values should give the height, and I want the plot to be colored based on the height values, with the z = 0 being pure white. In a similar vein, I want to construct the following contour plot as well.

ListPlot3D[data4, ColorFunction ->Blend[{{0.4, RGBColor[1,1,1], {0.3, RGBColor[1,0.9, 0.6]}, {0.3,RGBColor[0,0.7,0.9]}}], PlotLegends-> True, PlotRange -> {0,1}]

I get correct looking shapes for my plot, but the colors aren't applied at all. I just get solid color plots. I suspect it is beccause Blend[..] needs to be converted to a function and then applied to the z-values of the data, but I am unsure if this is indeed the correct way to do it, and if it is, I am not very confident with the syntax to do it.

$\endgroup$
0
1
$\begingroup$

If we want the z = 0 being pure white, I think we need to set {0,White} in the color settings.

SeedRandom[1]
data4 = RandomReal[{-1, 1}, {100, 3}];
colorSettings = {{0., RGBColor[1, 1, 1]}, {0.2, 
   RGBColor[1, 0.9, 0.6]}, {0.5, RGBColor[0, 0.7, 0.9]}}
ListPlot3D[data4, ColorFunction -> (Blend[colorSettings, #3] &), 
 PlotLegends -> True, PlotRange -> {0, 1}, Mesh -> None, 
 ClippingStyle -> None, ColorFunctionScaling -> True]

enter image description here

$\endgroup$
4
  • $\begingroup$ Thanks! this seems like a good answer. thanks for the tip on setting {0, White}, and clearing up the syntax. for (Blend[colorSettings, Abs@#3] &). This works for me for ListPlot3D but I get the following error Function::slotn: Slot number 3 in Blend[col,Abs[#3]]& cannot be filled from (Blend[col,Abs[#3]]&)[0.]. when I try to use it with ListContourPlot. If you can comment on this issue, i can select this as the accepted answer. Thank you so much! $\endgroup$
    – jcp
    Oct 20 '20 at 5:40
  • $\begingroup$ @jcp Remove Abs@ and try it again. $\endgroup$
    – cvgmt
    Oct 20 '20 at 5:45
  • $\begingroup$ @jcp Try this SeedRandom[1]; data4 = RandomReal[{-1, 1}, {100, 3}]; colorSettings = {{0., RGBColor[1, 1, 1]}, {0.2, RGBColor[1, 0.9, 0.6]}, {0.5, RGBColor[0, 0.7, 0.9]}}; ListPlot3D[data4, ColorFunction -> Function[{x, y, z}, Blend[colorSettings, z]], PlotLegends -> True, PlotRange -> {0, 1}, Mesh -> None, ClippingStyle -> None, ColorFunctionScaling -> True] $\endgroup$
    – cvgmt
    Oct 20 '20 at 7:24
  • $\begingroup$ Ah the issue is still with ListContourPlot[dummydata, ColorFunction -> Function[{p, q, r}, Blend[col, r]], PlotLegends -> True, PlotRange -> {0, 1}, Mesh -> None, ClippingStyle -> None, ColorFunctionScaling -> True]. with contour plot, i get Function::fpct: Too many parameters in {p,q,r} to be filled from Function[{p,q,r},Blend[col,r]][0.]. dummydata has the same shape as data4, namely dummydata = RandomReal[{-1, 1}, {100, 3}] $\endgroup$
    – jcp
    Oct 20 '20 at 16:58

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.