4
$\begingroup$

I came across Rojo's answer on the Mathematica Stack to the following questions:

"Estimating progress on plots"

Estimating progress on plots

Could somebody please help me revise this code for the Plot function:

SetAttributes[celtschkPlot, HoldAll];
celtschkPlot[fun_, {v_, r1__}, mr_: 6, op : OptionsPattern[]] := 
 Module[{i = 0, xant}, 
  Monitor[Plot[fun, {v, r1}, MaxRecursion -> mr, 
    EvaluationMonitor :> (If[v < xant, ++i]; xant = v), op], 
   ProgressIndicator[i, {0, 2^mr}]]]

to the ContourPlot function with two or three variables such as:

ContourPlot[x^2 - y^2, {x, -2, 2}, {y, -2, 2}, Contours -> {-1, 0, 1}] 

or

ContourPlot3D[x^2 + y^2 - z^2, {x, -2, 2}, {y, -2, 2},
     {z, -2, 2},Contours -> 5, Mesh -> None]

and please give me an usage example.

Thanks to Rojo and others in adavance.

I. Konuk

$\endgroup$

1 Answer 1

6
$\begingroup$

This should work, and it's pretty neat how it shows the recursive building up of the points.

SetAttributes[twoDProgressPlot, HoldAll];
twoDProgressPlot[plotfunc_, func_, {x_, xr__}, {y_, yr__}, 
  opts : OptionsPattern[]] :=
 Module[{pts},
  pts = {};
  Monitor[
   plotfunc[func, {x, xr}, {y, yr}, 
    EvaluationMonitor :> AppendTo[pts, {x, y}], opts], 
   Graphics[Point@pts, AspectRatio -> 1, Frame -> True, 
    PlotRange -> {{xr}, {yr}}]]
  ]

Here it is with a couple of examples,

twoDProgressPlot[DensityPlot, (Pause[.00002]; 
  Im[ArcTan[(x + I y)^3]]), {x, -2, 2}, {y, -2, 2}]



twoDProgressPlot[ContourPlot, (Pause[.0000002]; Cos[x] + Cos[y]), {x, 
  0, 4 π}, {y, 0, 4 π}]

enter image description here

$\endgroup$
5
  • $\begingroup$ Thank you very much. I have tried to extend your code to ContourPlot3D as: SetAttributes[tDProgressPlot, HoldAll]; tDProgressPlot[plotfunc_, func_, {x_, xr__}, {y_, yr__}, {z_, zr__}, opts : OptionsPattern[]] := Module[{pts}, pts = {}; Monitor[ plotfunc[func, {x, xr}, {y, yr}, {z, zr}, EvaluationMonitor :> AppendTo[pts, {x, y, z}], opts], Graphics[Point@pts, AspectRatio -> 1, Frame -> True, PlotRange -> {{xr}, {yr}, {zr}}]]] $\endgroup$
    – I. Konuk
    Commented May 18, 2016 at 18:10
  • $\begingroup$ @I.Konuk Great, does it work? Other functions that take 3 variables would be DensityPlot3D $\endgroup$
    – Jason B.
    Commented May 18, 2016 at 18:11
  • $\begingroup$ @I.Konuk You would need to change Graphics to Graphics3D I think $\endgroup$
    – Jason B.
    Commented May 18, 2016 at 18:13
  • $\begingroup$ Great. Many thanks indeed! $\endgroup$
    – I. Konuk
    Commented May 18, 2016 at 18:17
  • $\begingroup$ @I.Konuk - I fixed a couple of errors in your loglinearRegionPlot code, added it here $\endgroup$
    – Jason B.
    Commented Sep 22, 2016 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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