Note: The bug described in this post is found in Mathematica version 9 and seems to have been fixed in version 10.

Ok I don't know if it's a bug or what, but here's what I found:

If I use this function:

ContourPlot3D[Cos[2*Pi*z] + Cos[2*Pi*y] + Cos[2*Pi*x], {x, 0, 1}, {y, 0, 1}, {z, 0, 1}]

I get this error:

Rest::norest: Cannot take the rest of expression {} with length zero. >>

I have found that this issue is sometimes due to a need to use a numeric function. So I used:

ContourPlot3D[N[Cos[2*Pi*z] + Cos[2*Pi*y] + Cos[2*Pi*x]], {x, 0, 1}, {y, 0, 1}, {z, 0, 1}]

And I get this error:

Divide::indet: Indeterminate expression 0./0. encountered. >> Range::range: Range specification in Range[3.,3.,0.] does not have appropriate bounds. >>

I also tried:

ContourPlot3D[Cos[2*Pi*z?NumericQ] + Cos[2*Pi*y?NumericQ] + Cos[2*Pi*x?NumericQ], 
  {x, 0, 1}, {y, 0, 1}, {z, 0, 1}]

But I get:

ContourPlot3D::valuef: N[Cos[2 π z?NumericQ]+Cos[2 π y?NumericQ]+Cos[2 π x?NumericQ]] must be a numerical function. >>

However, if I try any of this:

ContourPlot3D[N[Cos[z] + Cos[y] + Cos[x]], {x, 0, 2*Pi}, {y, 0, 2*Pi}, {z, 0,2*Pi}]
ContourPlot3D[Cos[z] + Cos[y] + Cos[x], {x, 0, 2*Pi}, {y, 0, 2*Pi}, {z, 0, 2*Pi}]

I get no error what-so-ever. But the error with NumericQ persists. I'd also like to point out that the NumericQ error is the only one preventing me from getting the 3D graphics.

Does anybody know what's going on?

  • 1
    $\begingroup$ I Just added == 0 and no such error now. ContourPlot3D[Cos[2*Pi*z] + Cos[2*Pi*y] + Cos[2*Pi*x] == 0, {x, 0, 1}, {y, 0, 1}, {z, 0, 1}] gives !Mathematica graphics $\endgroup$ – Nasser Apr 13 '14 at 21:41
  • 1
    $\begingroup$ Is it really important what is going on? $\endgroup$ – Artes Apr 13 '14 at 21:41
  • 1
    $\begingroup$ As tot the ?NumericQ issue: You should not normally use a pattern test in a function call. You are confusing this with restrictions you put on function parameters in a function definition. $\endgroup$ – Sjoerd C. de Vries Apr 13 '14 at 21:54

What is going on?

By Trace-ing the ContourPlot3D, I found the warning (on my MMA) comes from a function System`ProtoPlotDump`findextreme (Hereafter, the context System`ProtoPlotDump` will be omitted for readability):

                {x_, xmin_, xmax_},
                {y_, ymin_, ymax_},
                {z_, zmin_, zmax_}
            }] := Quiet[
        Check[Through[{Min, Max}[Re[Table[f,
                                            {x, xmin, xmax},
                                            {y, ymin, ymax},
                                            {z, zmin, zmax}
                                         ]]]], None]]

findextreme[_] := None

This findextreme seems to be designed for finding the minimal and maximal value of the inputted function Cos[2 π z] + Cos[2 π y] + Cos[2 π x] over the plotting volume. But for OP's function, we have:

Table[Cos[2 π z] + Cos[2 π y] + Cos[2 π x], {x, 0, 1}, {y, 0, 1}, {z, 0, 1}]

{{{3, 3}, {3, 3}}, {{3, 3}, {3, 3}}}

Thus findextreme evaluated to {3, 3}.

Now, by checking the Stack[__] when the warning message arises, we can see there is a piece of code in the definition of a local variable defaultlabels$:

                Range[Sequence @@ extreme, Subtract @@ Reverse[extreme]/(3 + 1)]

where extreme is the result returned by findextreme. So the Range[...] part in the above code evaluated to

Range[3, 3, 0]

, or when N is applied on the inputted function:

Range[3., 3., 0.]

The former case goes to Rest[{}] and rises the Rest::norest warning, and the latter one itself rises the Divide::indet warning.

Temporary solution

By re-defining the findextreme function (i.e. using a random step size), I am able to avoid the problem described in OP:


                System`ProtoPlotDump`xmin_, System`ProtoPlotDump`xmax_},
                System`ProtoPlotDump`ymin_, System`ProtoPlotDump`ymax_},
                System`ProtoPlotDump`zmin_, System`ProtoPlotDump`zmax_}
            }] := Quiet[Check[Through[{Min, Max}[Re[Table[
                                System`ProtoPlotDump`xmin, System`ProtoPlotDump`xmax,
                                (System`ProtoPlotDump`xmax - System`ProtoPlotDump`xmin)/RandomReal[{2, 3}]
                                System`ProtoPlotDump`ymin, System`ProtoPlotDump`ymax,
                                (System`ProtoPlotDump`ymax - System`ProtoPlotDump`ymin)/RandomReal[{2, 3}]
                                System`ProtoPlotDump`zmin, System`ProtoPlotDump`zmax,
                                (System`ProtoPlotDump`zmax - System`ProtoPlotDump`zmin)/RandomReal[{2, 3}]
                            ]]]], None]]

System`ProtoPlotDump`findextreme[_] := None


The defaultlabels$ is used in code:

legendfront$ = 
            Legending`PlotLegendParser["Generic"][ContourPlot3D, legendData$, 
    Legended[plot$, legendfront$]

which suggests it might relate to automatic legend for ContourPlot3D, thus choosing the unit step size might has its reason. So re-defining findextreme may cause unpredictable consequence.

  • $\begingroup$ Have anyone else tested this solution? $\endgroup$ – Luciano Robino Apr 15 '14 at 0:16
  • $\begingroup$ @LucianoRobino This is the what I want to know... Anyway does it work for you? $\endgroup$ – Silvia Apr 15 '14 at 0:17
  • $\begingroup$ It work in my side for both cases. Although I was afraid to try it due to the unpredictable consequences for this minimal example it works fine. I'm not sure if I'll try it in the original file where the issue pop up $\endgroup$ – Luciano Robino Apr 15 '14 at 0:20
  • $\begingroup$ @LucianoRobino Great! :D And thanks for accepting. $\endgroup$ – Silvia Apr 15 '14 at 0:21
  • $\begingroup$ @LucianoRobino I think as long as you don't use legend on the outputted graphics, it will be safe. $\endgroup$ – Silvia Apr 18 '14 at 7:18

I got a result using Mathematica 9.01 . It is possible that you have an older version or missing libraries. Install flash in your computer to see if this might have to do with the graphic diver.

enter image description here

  • $\begingroup$ Interesting, my 9.0.1 home edition gives same warning as OP said. $\endgroup$ – Silvia Apr 14 '14 at 1:36
  • $\begingroup$ @Silvia, Jose: Could be an OS-dependent issue. Jose's screenshot appears to be taken on Windows, while I do get the warnings on my Mac. $\endgroup$ – user484 Apr 14 '14 at 1:39
  • $\begingroup$ @RahulNarain I'm on Windows 8 x64 .. $\endgroup$ – Silvia Apr 14 '14 at 1:41
  • $\begingroup$ Provide here the results of SystemInformation[] It will be interesting to compared the results from Sulvia and Rahul $\endgroup$ – Jose Enrique Calderon Apr 14 '14 at 5:06
  • $\begingroup$ I've Trace-d down to the source of the problem, will compose a post after lunch -- if no other answers appear then ;) $\endgroup$ – Silvia Apr 14 '14 at 5:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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