0
$\begingroup$

I would like to plot data so that the first column is in the x axis, the second column is in the y axis and the third column is the input for a custom ColorFunction. The ColorFunction is simple: white if the third column is 0 and increasingly darker shades of gray as values in the third column increase.

Part of my problem is that the data I am working with is not symmetric so I am having problems calling it.

Here is a MWE

list = {{{1, 1.5, 10}}, {{2, 1.5, 11}, {2, 1.4, 0}}, {{3, 1.5, 0}, {3,
     1.4, 0}, {3, 1.6, 11}}, {{4, 1.5, 0}, {4, 1.4, 0}, {4, 1.6, 
    13}, {4, 1.55, 0}}, {{5, 1.5, 0}, {5, 1.4, 0}, {5, 1.6, 0}, {5, 
    1.55, 0}, {5, 1.65, 13}}}

ListPlot[Flatten[list, 1][[All, {1, 2}]], 
 ColorFunction -> 
  If[Flatten[list, 1][[All, {3}]] > 0, ColorData["GrayTones"], 
   White], ColorFunctionScaling -> False]

I'm sure this will be quite simple for someone on here. Any suggestions are much appreciated

$\endgroup$

1 Answer 1

1
$\begingroup$
list0 = {{{1, 1.5, 10}}, {{2, 1.5, 11}, {2, 1.4, 0}}, {{3, 1.5, 
     0}, {3, 1.4, 0}, {3, 1.6, 11}}, {{4, 1.5, 0}, {4, 1.4, 0}, {4, 
     1.6, 13}, {4, 1.55, 0}}, {{5, 1.5, 0}, {5, 1.4, 0}, {5, 1.6, 
     0}, {5, 1.55, 0}, {5, 1.65, 13}}};

list = Flatten[list0, 1]
listNonZero = Cases[list, {_, _, Except[0 | 0.]}]

Remove unwanted points completely from the plot ...

ListPlot[Thread[{listNonZero[[All, {1, 2}]]}], 
 PlotStyle -> 
  Evaluate[ColorData["GrayTones"][1 - #] & /@ 
    Rescale[listNonZero[[All, 3]]]]]

Mathematica graphics

... or keep them in the plot and paint them white.

ListPlot[Thread[{list[[All, {1, 2}]]}], 
 PlotStyle -> 
  Evaluate[If[# > 0, ColorData["GrayTones"][1 - #], White] & /@ 
    Rescale[list[[All, 3]], MinMax[listNonZero[[All, 3]]]]]]

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ Thank you, this is very close. What I want is for points with 0 in the third column to be white and for points with nonzero third columns to be scaled so that higher values in the third column correspond to darker shades of gray $\endgroup$ Commented Sep 20, 2021 at 15:40
  • $\begingroup$ Oh, sorry, I was changing the code and then forgot about your non-zero condition. I have fixed my answer. $\endgroup$
    – Domen
    Commented Sep 20, 2021 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.