I have

ContourPlot[f[x, n], {x, 1, 6}, {n, 1, 500}, ColorFunction -> (If[# > 1, Lighter[RGBColor[1., 0.82, 0.57], 0.5*#], Lighter[RGBColor[0.5, 0.5, 0.85], #]] &), ColorFunctionScaling -> False, PlotLegends -> Automatic]

given f[x,n] is this complicated function

f[x_, n_] = (n*Pi*r^2*2/x*Exp[-x*Pi/2])/( L^2 *x*Exp[-x*Pi] + *L*Sqrt[1/Pi]*Exp[(-x*Pi)/2] + 16/(x*Pi)*Exp[-x*Pi/4])

though its particular nature is not important.

Can I add another if statement which "fades to greyscale" all parts of the contour plot that fulfill some condition (say x+n<102), while leaving the rest in the original colour (as given by the first condition?)

Below is what the first code snippet produces (where $\rho=x$).

phase plot of f[x,n]

  • $\begingroup$ "fades to grayscale" is sorta kinda vague; what sorts of gray are you expecting to come from your colors? $\endgroup$ – J. M.'s torpor Jul 29 '15 at 17:14
  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory Tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$ – bbgodfrey Jul 29 '15 at 17:15
  • $\begingroup$ @Guesswhoitis. the author wanted to edit-in "or simply removes the colorization", which isn't much better than "fades to grayscale", but I imagine, he wants to simply desaturate (as an image editor would do) those parts of the plot, where the condition is fulfilled. On a side note, in the comment to his edit he wrote, that he can't reply in comments as he doesn't have 50 rep. Bug on SE or he simply didn't try? $\endgroup$ – LLlAMnYP Jul 29 '15 at 17:37
  • $\begingroup$ @LLlAMnYP, prolly multiple account follies again. We can link the fellow to the account merging page if s/he shows up again. $\endgroup$ – J. M.'s torpor Jul 29 '15 at 17:40
  • $\begingroup$ In any case, that now looks like a conversion to HSB is needed. $\endgroup$ – J. M.'s torpor Jul 29 '15 at 17:42

I think this is what you're asking:

  Sin[x + y], {x, 0, 2 \[Pi]}, {y, 0, 2 \[Pi]}
  , RegionFunction -> (#1 + #2 < \[Pi] &)
  Sin[x + y], {x, 0, 2 \[Pi]}, {y, 0, 2 \[Pi]}
  , RegionFunction -> (#1 + #2 >= \[Pi] &)
  , ColorFunction -> GrayLevel

Where I've used RegionFunction to give the condition, and then used different color functions for each region.

enter image description here

  • $\begingroup$ Much as I don't like being made to read minds by askers, I wonder if what was desired was what the result of ColorConvert[color, GrayLevel] would be if it were only applied to a specific region… $\endgroup$ – J. M.'s torpor Jul 29 '15 at 17:26
  • $\begingroup$ I think, that's exactly what was meant. Also, I reckon, that is not exactly, what this answer achieves. $\endgroup$ – LLlAMnYP Jul 29 '15 at 17:46
  • 1
    $\begingroup$ I wonder if ContourPlot can be somehow hacked to accept more than one slot in the ColorFunction, that is have the color function dependent not just on contour levels, but simply coordinates on the graph too. $\endgroup$ – LLlAMnYP Jul 29 '15 at 17:51
  • $\begingroup$ OP can make his color function ColorFunction->(ColorConvert[f[#],"Grayscale"]&) if that's what was intended, it seems the trouble was more with attempting to specify regions in the color function based on the input variables instead of the output value. $\endgroup$ – N.J.Evans Jul 29 '15 at 17:53
  • $\begingroup$ @N.J.Evans yes, I think that would be the most valid way. Like I said, I wonder if it can be done in one line somehow. $\endgroup$ – LLlAMnYP Jul 29 '15 at 17: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.