From: Mark McClure on 22 Jul 2010 05:42 On Mon, Jul 19, 2010 at 2:10 AM, Kevin J. McCann <kjm(a)kevinmccann.com> wrote: > I have noticed the use of Directive in some of the graphics examples > from Bob Hanlon, David Park, and others. I am curious about this > command, since it does not appear to do much that is new. > ... > So, what is the benefit of Directive? Try Plot[{Cos[x], Sin[x]}, {x, 0, 2 Pi}, PlotStyle -> Directive[Thick, Red]] vs Plot[{Cos[x], Sin[x]}, {x, 0, 2 Pi}, PlotStyle -> List[Thick, Red]] Mark McClure
From: Brett Champion on 22 Jul 2010 05:42 On Jul 21, 2010, at 6:15 AM, Kevin J. McCann wrote: > Thanks Murray. I understand, but that seems like very little > improvement > at the cost of a new function. Surely, there must be more. BTW, I > think > I like the old way better - fewer keystrokes, and I am old > fashioned ;) > The advantage of Directive is that it removes ambiguity. Here are two plots with PlotStyle -> {Thick, Red}. In the first one, for legacy reasons, the Thick and Red are both applied to the curve. In the second the first curve is Thick (with the default used by Plot) and the second curve is Red (with the default line weight.) If you're building up your code, this can be a "gotcha". Plot[Sin[x], {x, 0, Pi}, PlotStyle -> {Thick, Red}] Plot[{Sin[x], Cos[x]}, {x, 0, Pi}, PlotStyle -> {Thick, Red}] If you want everything to be Red and Thick, Directive allows you to specify that clearly: Plot[Sin[x], {x, 0, Pi}, PlotStyle -> Directive[Thick, Red]] Plot[{Sin[x], Cos[x]}, {x, 0, Pi}, PlotStyle -> Directive[Thick, Red]] Most newer visualization functions only accept Directive as the way to specify multiple styles for a single object. BarChart[Range[5], ChartStyle -> {Orange, EdgeForm[Thick]}] BarChart[Range[5], ChartStyle -> Directive[Orange, EdgeForm[Thick]]] Brett Champion Wolfram Research > Kevin > > Murray Eisenberg wrote: >> In some situations, using Directive[opt1,opt2] instead of {opt1,opt2} >> can make code easier to read by avoiding nested parentheses. >> >> Compare, for example: >> >> Plot[{Sin[x],Cos[x]},{x,0,Pi},PlotStyle-> >> {Directive[Thick,Red],Directive[Thick,Dashed,Blue]}] >> >> Plot[{Sin[x], Cos[x]}, {x, 0, Pi}, >> PlotStyle -> {{Thick, Red}, {Thick, Dashed, Blue}}] >> >> On 7/19/2010 2:10 AM, Kevin J. McCann wrote: >>> I have noticed the use of Directive in some of the graphics examples >>> from Bob Hanlon, David Park, and others. I am curious about this >>> command, since it does not appear to do much that is new. For >>> example, >>> here is an example from the Help on Directive: >>> >>> Graphics[{Directive[Red, Thick], Circle[], >>> Directive[Blue, Opacity[0.5]], Rectangle[{0, -1}, {2, 1}]}] >>> >>> However, if I change to this, I get the same thing: >>> >>> Graphics[{Red, Thick, Circle[], Blue, Opacity[0.5], >>> Rectangle[{0, -1}, {2, 1}]}] >>> >>> So, what is the benefit of Directive? >>> >>> Thanks, >>> >>> Kevin >>> >> >
From: Kevin J. McCann on 23 Jul 2010 07:08 A couple have responded with something like Mark's example below. Is this really worth a new function and more keystrokes over: Plot[{Cos[x], Sin[x]}, {x, 0, 2 Pi}, PlotStyle -> {{Thick, Red}}] Kevin Mark McClure wrote: > On Mon, Jul 19, 2010 at 2:10 AM, Kevin J. McCann <kjm(a)kevinmccann.com> wrote: >> I have noticed the use of Directive in some of the graphics examples >> from Bob Hanlon, David Park, and others. I am curious about this >> command, since it does not appear to do much that is new. >> ... >> So, what is the benefit of Directive? > > Try > Plot[{Cos[x], Sin[x]}, {x, 0, 2 Pi}, > PlotStyle -> Directive[Thick, Red]] > vs > Plot[{Cos[x], Sin[x]}, {x, 0, 2 Pi}, > PlotStyle -> List[Thick, Red]] > > Mark McClure >
From: Bob Hanlon on 23 Jul 2010 07:10 However, the following with nested lists is equivalent to the use of Directive Plot[{Cos[x], Sin[x]}, {x, 0, 2 Pi}, PlotStyle -> {{Thick, Red}}] Bob Hanlon ---- Mark McClure <mcmcclur(a)unca.edu> wrote: ============= On Mon, Jul 19, 2010 at 2:10 AM, Kevin J. McCann <kjm(a)kevinmccann.com> wrote: > I have noticed the use of Directive in some of the graphics examples > from Bob Hanlon, David Park, and others. I am curious about this > command, since it does not appear to do much that is new. > ... > So, what is the benefit of Directive? Try Plot[{Cos[x], Sin[x]}, {x, 0, 2 Pi}, PlotStyle -> Directive[Thick, Red]] vs Plot[{Cos[x], Sin[x]}, {x, 0, 2 Pi}, PlotStyle -> List[Thick, Red]] Mark McClure
From: Mark McClure on 23 Jul 2010 07:11 On Thu, Jul 22, 2010 at 10:01 AM, Kevin J. McCann <Kevin.McCann(a)umbc.edu> w= rote: > A couple have responded with something like Mark's example below. Is this > really worth a new function and more keystrokes over: > > Plot[{Cos[x], Sin[x]}, {x, 0, 2 Pi}, > PlotStyle -> {{Thick, Red}}] I still rather like Directive, primarily due to it's clarity. It certainly follows Wolfram's TypeExactlyWhatYouMean philosophy. >From a programmatic perspective, it can be convenient to encase directives in a head other than List. It makes it easier to use Cases or DeleteCases to scan for directives, for example. Here's an example where we use Inner to combine some graphics primitives and graphics directives. The fact that the head Directive is different from the head List is essential. I don't think you can change the Directive head to either a List or nested Lists. Graphics[ Inner[List, { Directive[Red, PointSize[Large]], Directive[Blue, PointSize[Medium]] }, {Point[{0, 0}], Point[{1, 0}]}, List], AspectRatio -> 1/10] Of course, if you prefer Lists when appropriate, then have at it! :) Mark
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: Problems with Workbench Debugger Breakpoints Next: Multiple packages in a single application |