From: Murray Eisenberg on 23 Jul 2010 07:12 Good example! Of course one _could_ still dispense with Directive in the first one, using instead... Plot[{Cos[x], Sin[x]}, {x, 0, 2 Pi}, PlotStyle -> {{Thick, Red}}] .... with the nested PlotStyle value. And here, too, the point is that Directive provides a convenience of eliminating nested braces. Just because a function such as Directive in such situations is a mere convenience and not indispensable does not militate against its existence. After all, some other newer functions such as Total or Accumulate are also dispensable but nonetheless conveniences. If you want to stick with fewer functions, just go ahead and use the nested parentheses. On 7/22/2010 5:42 AM, 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 > -- Murray Eisenberg murray(a)math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305
From: Murray Eisenberg on 24 Jul 2010 05:05 Fewer keystrokes is not the sole metric for simplicity! Code readability is another. On 7/23/2010 7:09 AM, Kevin J. McCann wrote: > 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 >> > -- Murray Eisenberg murray(a)math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305
From: Helen Read on 24 Jul 2010 05:08 On 7/23/2010 7:12 AM, Murray Eisenberg wrote: > Good example! Of course one _could_ still dispense with Directive in the > first one, using instead... > > Plot[{Cos[x], Sin[x]}, {x, 0, 2 Pi}, PlotStyle -> {{Thick, Red}}] > > ... with the nested PlotStyle value. And here, too, the point is that > Directive provides a convenience of eliminating nested braces. > > Just because a function such as Directive in such situations is a mere > convenience and not indispensable does not militate against its > existence. After all, some other newer functions such as Total or > Accumulate are also dispensable but nonetheless conveniences. > > If you want to stick with fewer functions, just go ahead and use the > nested parentheses. Brett Champion's post from 7/22 sheds light on this. He explains that Directive is intended to remove ambiguity. The old behavior in Plot (and other existing functions) has been kept for legacy reasons. Most of the new functions require Directive for specifying multiple styles for a single item. Try Brett's example: BarChart[Range[5], ChartStyle -> {Orange, EdgeForm[Thick]}] BarChart[Range[5], ChartStyle -> {{Orange, EdgeForm[Thick]}}] Compare: BarChart[Range[5], ChartStyle -> Directive[Orange, EdgeForm[Thick]]] -- Helen Read University of Vermont
From: Kevin J. McCann on 24 Jul 2010 05:08 I remain unconvinced. As I said earlier, I don't think that the examples I have seen do much more than replace the extra wiggly brackets, "{}", with more keystrokes "Directive[]". I don't find it easier to read. My original post was not to say that the examples you show are not valid, I just wondered if the folks at Wolfram went to the trouble of defining a new function for more than just that. As far as Total goes, that is much more intuitive than Plus @@, but the use of the word Directive, at least to me, is not intuitive and requires that I look it up in the Help. Kevin Murray Eisenberg wrote: > Good example! Of course one _could_ still dispense with Directive in the > first one, using instead... > > Plot[{Cos[x], Sin[x]}, {x, 0, 2 Pi}, PlotStyle -> {{Thick, Red}}] > > ... with the nested PlotStyle value. And here, too, the point is that > Directive provides a convenience of eliminating nested braces. > > Just because a function such as Directive in such situations is a mere > convenience and not indispensable does not militate against its > existence. After all, some other newer functions such as Total or > Accumulate are also dispensable but nonetheless conveniences. > > If you want to stick with fewer functions, just go ahead and use the > nested parentheses. > > On 7/22/2010 5:42 AM, 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: Kevin J. McCann on 24 Jul 2010 05:08 Mark, I'll agree that your example with the use of the Inner product is a clever way to do that, but isn't this way more readable? Graphics[{ Red,PointSize[Large],Point[{0,0}], Blue,PointSize[Medium],Point[{1,0}] }, AspectRatio->1/10] Seems like a lot of overhead with the use of Inner and Directive. But if you prefer more keystrokes and the use of two additional functions (Inner, Directive) Graphics[ Inner[List, { Directive[Red, PointSize[Large]], Directive[Blue, PointSize[Medium]] }, {Point[{0, 0}], Point[{1, 0}]}, List], AspectRatio -> 1/10] then have at it ;) Kevin Mark McClure wrote: > 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 |