0
$\begingroup$

Starting point

Function of interest: $$ f(x,y)=-\frac{2 x^5+x y+2 y^7}{x^2+y^2} $$

f[x_, y_] = -((2 x^5 + x y + 2 y^7)/(x^2 + y^2))

ContourPlot:

ContourPlot[(x (-2 x^4 + y) + y (-2 x - 2 y^6))/(x^2 + y^2), {x, -2, 2}, {y, -2, 2}]

yuk

The purpose of the plot is to distinguish regions where $f(x,y) > 0$ from regions where $f(x,y) < 0$ using two different colors. Perhaps blue for positive, red for negative. The brightness can be a scale. Very blue is very positive. Near $0$, both colors are extremely faint.

Question: How can we write a ColorFunction for ContourPlot which allows a combination of two monochromatic brightness gradients?

The ultimate goal is to produce as aesthetically pleasing chart that quickly lets the user sort positive from negative regions. Unleash your inner aesthete if you have a grander scheme


Didn't see how to get there starting here How can I combine two color schemes for plotting?
@David G. Stork has a great idea, shown below. A dab of polish is needed to get the red colors to appear in negative land and to make the higher values darker, not lighter. (Contour labels added for debugging.)

david

$\endgroup$
2
  • $\begingroup$ What color do you want at zero? $\endgroup$ May 12, 2017 at 21:31
  • $\begingroup$ @David G. Stork: At the risk of being a Philistine, my first thought was to have a very light shading. Red if negative, blue if positive. The final plot will include a thick line for the contour of 0 value which will provide a strong demarcation. Better ideas are always welcome. $\endgroup$
    – dantopa
    May 12, 2017 at 21:45

1 Answer 1

-1
$\begingroup$
ContourPlot[(x (-2 x^4 + y) + y (-2 x - 2 y^6))/(x^2 + y^2), {x, -2, 
  2}, {y, -2, 2}, 
 ColorFunction -> (If[#1 > 0, Blend[{Blue, White}, #1], 
     Blend[{Red, White}, Abs[#1]]] &),
 Mesh -> 1,
 MeshFunctions -> (#3 &),
 MeshStyle -> {Thick, Green}]

with a thick green line at $z = 0$.

Personally, I prefer this plot:

Plot3D[(x (-2 x^4 + y) + y (-2 x - 2 y^6))/(x^2 + y^2),
 {x, -2, 2}, {y, -2, 2}, 
 ColorFunction -> (If[#1 > 0, Blend[{Blue, White}, #1], 
     Blend[{Red, White}, Abs[#1]]] &),
 MeshFunctions -> (#3 &),
 Mesh -> 1,
 MeshStyle -> {Thickness[0.02], Green}]
$\endgroup$

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