Group Abstract Group Abstract

Message Boards Message Boards

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

Set colors of a surface z=f(x,y) according to y value

Posted 5 years ago

Good evening everyone,

I spent all day trying to properly show and format the following surface

z^2=y-1/x^3

I have the following problems that I haven't solved yet:

  • I have to plot the surface with a top view and see the couples (x,y). Is ContourPlot the right function? (Look up following point)
  • I have to set different colors for the surface according to value of y. y < 0 DarkRed to LightRed, y=0 Green, y > 0 lightBlue to DarkBlue. Any idea on how to do that?
  • Respect the given plot range, i.e. {-10,10} for x and y.

Any sort of help or idea will be extremely appreciated. Thank you all.

Antonio

X = {x,-10,10};
Y = {y,-10,0};
W = {y,0,10};

Show[{ContourPlot[(y+1/x^3)^0.5, X, Y,ContourStyle -> Red],
1ContourPlot[(y+1/x^3)^0.5, X, Z, ContourStyle ->Blue],
ContourPlot[B(1/x^3) ,X,Y, ContourStyle -> Green,BaseStyle -> Thick]},
RotateLabel -> False, FrameLabel -> {"r", "r^."}, PlotRange->Full
]
POSTED BY: Antonio Cillis
5 Replies

First: x == 0 is a singularity, your surface is not defined.

Second: look at this, does that help (I avoided x == 0 , therefore two plots)?

p1 = ContourPlot3D[
  z^2 - y + 1/x^3 == 0, {x, -10, -.2}, {y, -10, 10}, {z, -10, 10}, 
  Mesh -> False,
  ColorFunction -> Function[{x, y, z}, If[y < 0, Red, Blue]],
  ColorFunctionScaling -> False]
p2 = ContourPlot3D[
  z^2 - y + 1/x^3 == 0, {x, .2, 10}, {y, -10, 10}, {z, -10, 10}, 
  Mesh -> False,
  ColorFunction -> Function[{x, y, z}, If[x > 0, Magenta, Blue]],
  ColorFunctionScaling -> False]
Show[p2, p1, PlotRange -> All]
POSTED BY: Hans Dolhaine
Posted 5 years ago

Two things:

  1. Your Cartesian equation can be explicitly solved for $y$, so you can either a. use Plot3D[] and rotate the surface afterwards; or b. use ParametricPlot3D[] directly.

  2. You can directly construct an appropriate ColorFunction by using Darker[] with some function that asymptotically approaches $1$:

Thus:

ParametricPlot3D[{x, z^2 + 1/x^3, z}, {x, -10, 10}, {z, -10, 10}, 
                 ColorFunction -> Function[{x, y, z},
                                           If[y == 0, Green,
                                              Darker[If[y > 0, Blue, Red],
                                                     Tanh[Abs[y]/10]]]], 
                 ColorFunctionScaling -> False, Mesh -> False, PlotPoints -> 45, 
                 PlotRange -> 10]

(I'm not able to run this on Mathematica at the moment, so please adjust the ColorFunction and PlotPoints settings to your taste.)

POSTED BY: J. M.

You may want to look at the peculiar behaviour of your surface-equation by

Manipulate[
 Plot[Sqrt[y - 1/x^3], {x, -10, 10}, PlotRange -> {-1, 1}],
 {y, -10, 10}]

Another way to plot it without Show (avoiding the split in two plots due to the singularity) is

p3 = ContourPlot3D[
  x^3 (z^2 - y) + 1 == 0, {x, -10, 10}, {y, -10, 10}, {z, -10, 10}, 
  Mesh -> False, 
  ColorFunction -> 
   Function[{x, y, z}, 
    Which[y < 0 && x < 0, Blue, y > 0 && x < 0, Red, x > 0, Magenta]],
   ColorFunctionScaling -> False, PlotPoints -> 30]
POSTED BY: Hans Dolhaine

Hello Antonio,

Merry Xmas.

I don't get what you really want to see in your plot.

I tried this

p4 = ContourPlot3D[
  x^3 (z^2 - y) + 1 == 0, {x, -10, 10}, {y, -10, 10}, {z, -10, 10}, 
  Mesh -> False, 
  ColorFunction -> 
   Function[{x, y, z}, 
    Which[y < 0 && x < 0, {Opacity[.5], Blue}, 
     y > 0 && x < 0, {Opacity[.5], Red}, 
     x > 0, {Opacity[.5], Magenta}]], ColorFunctionScaling -> False, 
  PlotPoints -> 30,
  ViewPoint -> {5.8, -7.6, 3}]

Looking form "above" you will not see the parts with z < 0. So

p5 = ContourPlot3D[
  x^3 (z^2 - y) + 1 == 0, {x, -10, 10}, {y, -10, 10}, {z, 0, 10}, 
  Mesh -> False, 
  ColorFunction -> 
   Function[{x, y, z}, 
    Which[y < 0 && x < 0, {Opacity[.5], Blue}, 
     y > 0 && x < 0, {Opacity[.5], Red}, 
     x > 0, {Opacity[.5], Magenta}]], ColorFunctionScaling -> False, 
  PlotPoints -> 30,
  ViewPoint -> {5.8, -7.6, 3}]  

or (??)

p6 = ContourPlot3D[
  x^3 (z^2 - y) + 1 == 0, {x, -10, 10}, {y, -10, 10}, {z, 0, 10}, 
  Mesh -> False, 
  ColorFunction -> 
   Function[{x, y, z}, 
    Which[y < 0 && x < 0, {Opacity[.2], Blue}, 
     y > 0 && x < 0, {Opacity[.9], Red}, 
     x > 0, {Opacity[.9], Magenta}]], ColorFunctionScaling -> False, 
  PlotPoints -> 50,
  ViewPoint -> {0, 0, 5}, Boxed -> False]

Or do you prefer something like this?

Plot3D[Sqrt[y - 1/x^3], {x, -10, 10}, {y, -10, 10}, PlotPoints -> 30,
 ColorFunction -> Function[{x, y, z}, If[y < 0, Red, Blue]], 
 ColorFunctionScaling -> False, AxesLabel -> {x, y, z}]

And you could add coordinatelines

p7 = Show[
  ContourPlot3D[
   x^3 (z^2 - y) + 1 == 0, {x, -10, 10}, {y, -10, 10}, {z, -10, 10}, 
   Mesh -> False, 
   ColorFunction -> 
    Function[{x, y, z}, 
     Which[y < 0 && x < 0, {Opacity[.5], Blue}, 
      y > 0 && x < 0, {Opacity[.5], Red}, 
      x > 0, {Opacity[.5], Magenta}]], ColorFunctionScaling -> False, 
   PlotPoints -> 30,
   ViewPoint -> {5.8, -7.6, 3}],
  Graphics3D[{Thick, Line[{{-10, 0, 0}, {10, 0, 0}}], 
    Line[{{0, -10, 0}, {0, 10, 0}}], Line[{{0, 0, -10}, {0, 0, 10}}]}]
  ]
POSTED BY: Hans Dolhaine
Posted 5 years ago

Hi Hans, thank you very much for your answear. I haven't been using mathematica for a while, and I was and I am a complete beginner with this programming language.

Back to my question: I knew there was a singularity in x == 0, but the plot was intented to rapresent a thing called Phase Portrait. Within this context, I have to show three zones for the surface, one of whom where the transition happens at y=0. This should be achieved by using your p3 proposal and setting up different conditions. Since I need the top view, which option should I be using? I used ViewPoint but it gives an unpleasant 3D pespective, like in ControurPlot.

Once again, thank you very much for your help and the time you dedicated me :)

Result ViewPoint

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