Message Boards Message Boards

GROUPS:

How to Avoid Plotting when output axis = 0 with Plot3D[]?

Posted 9 years ago
4320 Views
|
6 Replies
|
8 Total Likes
|

Would like the plot below to only display when the output (i.e. the vertical axis) is not equal to zero. Experimented with 'RegionFunction' option but it hasn't been working. How might I get this to work?

Show[
 Plot3D[
  If[
   Last[Flatten[NSolve[p == x*Log[t + 1], x, Reals]]][[2]] > 6,
   1,
   If[
    Last[Flatten[NSolve[p == x*Log[t + 1], x, Reals]]][[2]] < -0.25,
    0,
    Last[Flatten[NSolve[p == x*Log[t + 1], x, Reals]]][[2]]]]
  , {t, 0, 5.4}, {p, -1, 1}
  , PlotStyle -> Opacity[0.35]
  , FaceGrids -> All
  , PerformanceGoal -> "Quality"
  , ColorFunction -> "Rainbow", PlotLegends -> Automatic
  , PlotTheme -> "Web"
  , ImageSize -> 700
  , BoundaryStyle -> Thick
  , AxesLabel -> Automatic
  , RegionFunction -> Function[{z}, 0 <= z ]
  ]
 , PlotRange -> {{0, 5.4}, {-1, 1}, {-1, 1}}]
Attachments:
POSTED BY: Greg
6 Replies
Posted 9 years ago

I see that. Thanks for the clarification. It does work well for my purposes, as I was using zero for the "not interested" part of the surface, and just wanted to "hide" it. I'll include the image here to conclude this for others' sake. Removing 'RegionFunction' of course, since it is superfluous.

Attachments:
POSTED BY: Greg

So this won't work unless you have a large region that's actually just 0. If Plot3D doesn't evaluate Sin[x + y^2] /. {0 -> Indeterminate} at a point that produces exactly 0 them it won't work.

So you'll see it work here:

Show[Plot3D[
  If[Last[Flatten[NSolve[p == x*Log[t + 1], x, Reals]]][[2]] > 6, 1, 
    If[Last[Flatten[
         NSolve[p == x*Log[t + 1], x, Reals]]][[2]] < -0.25, 0, 
     Last[Flatten[
        NSolve[p == x*Log[t + 1], x, Reals]]][[2]]]] /. {0 -> 
     Infinity}, {t, 0, 5.4}, {p, -1, 1}, PlotStyle -> Opacity[0.35], 
  FaceGrids -> All, PerformanceGoal -> "Quality", 
  ColorFunction -> "Rainbow", PlotLegends -> Automatic, 
  PlotTheme -> "Web", ImageSize -> 700, BoundaryStyle -> Thick, 
  AxesLabel -> Automatic, RegionFunction -> Function[{z}, 0 <= z]], 
 PlotRange -> {{0, 5.4}, {-1, 1}, {-1, 1}}]

But... I mean maybe it'd be easier to use an If Statement instead of Replace (/.)

Plot3D[Sin[x + y^2] /. {num_ /; Abs[num] < 0.1 -> Indeterminate}, {x, -3,  3}, {y, -2, 2}]
POSTED BY: Sean Clarke

If the first argument to Plot3D is X then make the first argument to Plot3D :

X/.{0 -> Indeterminate}

Essentially just append "/.{0 -> Indeterminate}" to the first argument of Plot3D.

POSTED BY: Sean Clarke
Posted 9 years ago

Sorry, that's why I'm asking the question. How would it look to fit "X/.{0->Indeterminate}" into Plot3D[]?

A simpler starting point,

Plot3D[Sin[x + y^2] , {x, -3, 3}, {y, -2, 2}]

My interpretation of what you are explaining, which is not working as intended,

Plot3D[Sin[x + y^2] /. {0 -> Indeterminate}, {x, -3, 3}, {y, -2, 2}]

And the application of RegionFunction, which is working as shown,

Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}, 
 RegionFunction -> Function[{x, y, z}, z > 0.2 || z < -0.2]]
Attachments:
POSTED BY: Greg

I tried a couple of things with RegionFunction. Using z!=0 doesn't work. It knows that's an infinitely thin region. Something with some thickness however will work:

RegionFunction -> Function[{x, y, z}, z > 0.01 || z < -0.01]

I think a simpler solution to the problem is to make the function being plotted just not exist in the plotting range when it actually equals zero. Basically you just have the function being plotted return Infinity or Indeterminate instead of 0:

Plot3D[function /. {0 -> Indeterminate}, {t, 0, 5.4}, {p, -1, 1}, ...]
POSTED BY: Sean Clarke
Posted 9 years ago

That looks like a great solution. I tried setting that inside of the above code, but haven't gotten it to take. Would you mind showing how these can be included within the above code?

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

Group Abstract Group Abstract