Group Abstract Group Abstract

Message Boards Message Boards

0
|
7.9K Views
|
5 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Plot3D with different colors for positive and negative values of z?

Posted 6 years ago

I am plotting a function z=f(x,y) using Plot3D.

Plot3D[x^2 + y^2 - 100, {x, 1, 10}, {y, 1, 10}]

How can I have different colors for positive and negative values of z? Many thanks in advance. Sincerely, Cuneyt

POSTED BY: Cuneyt Eroglu
5 Replies
Posted 6 years ago

Much better! Thanks, Neil!

POSTED BY: Cuneyt Eroglu

@ Neil: thanks a lot. I didn't know that, and I think it is not written very clearly in the "Help" ( Version 7.0 ). So I overlooked that.

@Cuneyt

Is this better?

Plot3D[x^2 + y^2 - 100, {x, 1, 10}, {y, 1, 10}, 
ColorFunction -> Function[{x, y, z}, If[z > 0, Red, Blue]], 
ColorFunctionScaling -> False, PlotPoints -> 100]
POSTED BY: Hans Dolhaine

Hans,

You always need to use ColorFunctionScaling->False if you want to use absolute number values from the function.

This works:

Plot3D[x^2 + y^2 - 100, {x, 1, 10}, {y, 1, 10}, 
 ColorFunction -> Function[{x, y, z}, If[z > 0, Hue[0.2], Hue[0.5]]], 
 ColorFunctionScaling -> False]

or

Plot3D[x^2 + y^2 - 100, {x, 1, 10}, {y, 1, 10}, 
 ColorFunction -> Function[{x, y, z}, If[z > 0, Red, Blue]], 
 ColorFunctionScaling -> False]

Regards,

Neil

POSTED BY: Neil Singer
Posted 6 years ago

Hans and Neil,

Thank you both for your responses. I have one more quick question. The boundary between the two colors is blurry. Is there a way to fix that?

Sincerely, Cuneyt

POSTED BY: Cuneyt Eroglu
Plot3D[x^2 + y^2 - 100, {x, 1, 10}, {y, 1, 10},  ColorFunction -> Function[{x, y, z}, Hue[z]]]

But I have no idea why this doesn't work (at least on my system: Mma 7.0)

Plot3D[x^2 + y^2 - 100, {x, 1, 10}, {y, 1, 10},  ColorFunction -> Function[{x, y, z}, If[z > 0, Hue[.02], Hue[.5]]]]

Does somebody know?

POSTED BY: Hans Dolhaine
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard