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

**URL:** <https://community.wolfram.com/t/how-to-avoid-plotting-when-output-axis-0-with-plot3d/4869>\
**Category:** Questions\
**Tags:** mathematica, graphics-and-visualization\
**Created:** [February 17, 2015, 3:31am UTC](https://community.wolfram.com/t/how-to-avoid-plotting-when-output-axis-0-with-plot3d/4869 "2015-02-17T03:31:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregwhammond](https://avatars.discourse-cdn.com/v4/letter/g/96bed5/32.png) [@gregwhammond](https://community.wolfram.com/u/gregwhammond)\
**Post date:** [February 17, 2015, 3:31am UTC](https://community.wolfram.com/t/how-to-avoid-plotting-when-output-axis-0-with-plot3d/4869/1 "2015-02-17T03:31:29Z")

</div>

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?

```auto
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}}]

```

---

<div class="post-metadata">

**Author:** ![seanc](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/seanc/32/34005_2.png) [@seanc](https://community.wolfram.com/u/seanc)\
**Post date:** [February 17, 2015, 4:04am UTC](https://community.wolfram.com/t/how-to-avoid-plotting-when-output-axis-0-with-plot3d/4869/2 "2015-02-17T04:04:42Z")

</div>

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}, ...]

```

---

<div class="post-metadata">

**Author:** ![gregwhammond](https://avatars.discourse-cdn.com/v4/letter/g/96bed5/32.png) [@gregwhammond](https://community.wolfram.com/u/gregwhammond)\
**Post date:** [February 17, 2015, 4:17am UTC](https://community.wolfram.com/t/how-to-avoid-plotting-when-output-axis-0-with-plot3d/4869/3 "2015-02-17T04:17:42Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![seanc](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/seanc/32/34005_2.png) [@seanc](https://community.wolfram.com/u/seanc)\
**Post date:** [February 17, 2015, 4:30am UTC](https://community.wolfram.com/t/how-to-avoid-plotting-when-output-axis-0-with-plot3d/4869/4 "2015-02-17T04:30:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gregwhammond](https://avatars.discourse-cdn.com/v4/letter/g/96bed5/32.png) [@gregwhammond](https://community.wolfram.com/u/gregwhammond)\
**Post date:** [February 17, 2015, 5:00am UTC](https://community.wolfram.com/t/how-to-avoid-plotting-when-output-axis-0-with-plot3d/4869/5 "2015-02-17T05:00:28Z")

</div>

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

A simpler starting point,

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

```

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

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

```

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

```auto
Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}, 
 RegionFunction -> Function[{x, y, z}, z > 0.2 || z < -0.2]]

```

---

<div class="post-metadata">

**Author:** ![seanc](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/seanc/32/34005_2.png) [@seanc](https://community.wolfram.com/u/seanc)\
**Post date:** [February 17, 2015, 5:23am UTC](https://community.wolfram.com/t/how-to-avoid-plotting-when-output-axis-0-with-plot3d/4869/6 "2015-02-17T05:23:29Z")

</div>

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}]

```

---

<div class="post-metadata">

**Author:** ![gregwhammond](https://avatars.discourse-cdn.com/v4/letter/g/96bed5/32.png) [@gregwhammond](https://community.wolfram.com/u/gregwhammond)\
**Post date:** [February 17, 2015, 7:57am UTC](https://community.wolfram.com/t/how-to-avoid-plotting-when-output-axis-0-with-plot3d/4869/7 "2015-02-17T07:57:40Z")

</div>

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.
