Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Improving Plot evaluation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg13843] Improving Plot evaluation
  • From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
  • Date: Sat, 29 Aug 1998 04:41:19 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

A frequent source of frustration among novice users is the trouble they
have when they try to make a plot using:
Plot[ D[Sin[x],x]  , {x,0, 2 Pi}]

The key here is to wrap the first argument in Evaluate.  There are
several other situations where you have to use Evaluate inside Plot. 
Apparently the reason Plot holds it's arguments is to ensure it
produces a nice plot in cases such as:
Plot[  NIntegrate[Sin[Sin[t x]],{t,0,1}],  {x,0, Pi}]  

As a more experienced user I have been frustrated that the kernel can't
figure out what needs to be held and what needs to be evaluated.  I
figured out a slick way to eliminate the need to use Evaluate inside
Plot with no downside (as far as I can tell).  My program to do this is
in the lines below.

_____________________

In[1]:=
$PreevaluatePlotArguments=True;
Unprotect[Plot];
 
Plot[f_,{x_,xmin_,xmax_},opts___?OptionQ]/;
      $PreevaluatePlotArguments:=
  Block[{$PreevaluatePlotArguments},
     Plot@@Block[{Message, x},Hold@@{f,{x,xmin,xmax},opts}]
  ]
				
Protect[Plot];
_____________________

Using my definitions for Plot I get the expected graphics from In[3] and
In[4] below.
I even get the expected graphic for something really troublesome such as
the problem at In[5].

_____________________

In[3]:=
Plot[ D[Sin[x],x],{x,0,2 Pi}];

(*  A nice Graphic not shown.   *)
_____________________


In[4]:=
Plot[NIntegrate[Sin[Sin[t x]],{t,0,1}],   {x,0,Pi}];

(*  A nice Graphic not shown.   *)
_____________________


In[5]:=
funcs[x_]:=
   {  D[Sin[x],x], NIntegrate[Sin[Sin[t x]],{t,0,1}]  };

Plot[funcs[x],{x,0, Pi}, 
   PlotStyle->{Dashing[{0.02,0.02}],Hue[0.7]}];

(*  A nice Graphic not shown.   *)

_______________________

Other functions that could benefit from the same enhancement are:
Plot3D, ParametricPlot, ParametricPlot3D, DensityPlot, Play,
ContourPlot, SampledSoundFunction,
Product, Sum, NIntegrate, FindRoot, NSum, NProduct ,Table, FindMinimum.

I am looking forward to some feedback on this subject.  Please let me
know if you see any problems with my program.

Ted Ersek



  • Prev by Date: Re: Help: How to add label such as "alpha" in plotting?
  • Next by Date: An operator called-- LocalSet
  • Previous by thread: StyleSheets and Palettes in your application
  • Next by thread: An operator called-- LocalSet