MathGroup Archive 2010

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

Search the Archive

Re: Re: Re: How to combine graphics

  • To: mathgroup at smc.vnet.net
  • Subject: [mg107128] Re: [mg107089] Re: [mg107024] Re: [mg107011] How to combine graphics
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Wed, 3 Feb 2010 06:12:13 -0500 (EST)
  • References: <201001311253.HAA14187@smc.vnet.net>
  • Reply-to: drmajorbob at yahoo.com

I'd forgotten about Draw2D's scoping of directives in sublists.

Bobby

On Tue, 02 Feb 2010 02:30:03 -0600, Murray Eisenberg  
<murray at math.umass.edu> wrote:

> Bobby,
>
> As a devoted and experienced user of Presentations, of course I'm well
> aware that enlisting Red and Line[points] is unnecessary.
>
> However, as a matter of my programming style preferences and to avoid
> unwanted effects, I make it a practice whenever I can to use the extra
> list, as in
>
>    Draw2D[{Draw[Sin[x], {x, -Pi, Pi}], {Red,Line[points]}}, Axes -> True]
>
> or at the very least to pretty-print my expression in a form such as
>
>    Draw2D[{
>      Draw[Sin[x], {x, -Pi, Pi}],
>      Red, Line[points]
>      }, Axes -> True]
>
> so as clarify that the intention is to apply the Red directive to what
> follows immediately (on the same line).
>
> If one avoids the extra braces, then the avoidance of unwanted effects
> occurs in something like the following:
>
>     Draw2D[{Draw[Sin[x],{x,-Pi,Pi}],Red,Line[points],
>             Draw[x^2, {x,-Pi,Pi}]},Axes->True]
>
> As it stands, the parabola would be drawn in Red, too; that may or may
> not be what was really intended.  Using the extra list --
>
>     Draw2D[{Draw[Sin[x],{x,-Pi,Pi}],{Red,Line[points]},
>             Draw[x^2, {x,-Pi,Pi}]},Axes->True]
>
> -- avoids the problem, as of course does the alternative of explicitly
> changing color back again:
>
>     Draw2D[{Draw[Sin[x],{x,-Pi,Pi}],
>             Red,Line[points],
>             Black, Draw[x^2, {x,-Pi,Pi}]},Axes->True]
>
> I have no objection to the latter but prefer to use it when I want yet a
> third color for the third graphics object.
>
> Presentations allows those variants all to work, to suit one's fancy,
> while still allowing with all its oh-so-useful paradigm of simply
> listing the graphics objects and directives one after the other.
>
> Murray
> On 2/1/2010 8:54 PM, DrMajorBob wrote:
>> Presentations gives the same graph with even LESS complexity, too:
>>
>> Draw2D[{Draw[Sin[x], {x, -Pi, Pi}], Red, Line[points]}, Axes -> True]
>>
>> (No need to put Red and Line in a List together.)
>>
>> I think David deliberately made Draw2D's argument a List in order to
>> emphasize this point, or something like it. Directives and graphics are
>> sequentially applied, and Draw2D options apply to the overall drawing.
>>
>> This works just as we'd expect it to, as well:
>>
>> Draw2D[{Blue, Draw[Sin[x], {x, -Pi, Pi}], Red, Line[points],
>> Draw[Cos[x], {x, -Pi, Pi}]}, Axes -> True]
>>
>> and so does this:
>>
>> Draw2D[{Blue, Draw[Sin[x], {x, -Pi, Pi}], Red, Line[points],
>> Draw[Cos[x], {x, -Pi, Pi}]}, Axes -> True, AxesStyle -> Purple,
>> Background -> LightPink]
>>
>> Bobby
>>
>> On Mon, 01 Feb 2010 05:09:40 -0600, Murray Eisenberg
>> <murray at math.umass.edu> wrote:
>>
>>> Trying to do this kind of thing using Mathematica's built-in paradigm
>>> for graphics causes trouble for many beginners.
>>>
>>> Here's one way. (I changed the x-domain because otherwise the random
>>> polygon collapses to a small blur.)
>>>
>>> points = RandomReal[{-1,1},{100,2}];
>>> Show[{
>>> Plot[Sin[x],{x,-Pi,Pi}],
>>> Graphics[{Red,Line[points]}]
>>> }]
>>>
>>> The Graphics has to apply only to the {Red,Line[points]}, as the result
>>> of the Plot expression is already a Graphics object.
>>>
>>> You don't need the Axes->True option, as that's the default for Plot.
>>> However -- and this really drives folks nuts -- if you reverse the  
>>> order
>>> of the Graphics objects...
>>>
>>> Show[{Graphics[{Red,Line[points]}], Plot[Sin[x], {x,-Pi,Pi}]}]
>>>
>>> ... then the axes disappear and you have to insert the Axes->True  
>>> option
>>> within the Graphics[{Red,Line[points]}] expression:
>>>
>>> Show[{Graphics[{Red, Line[points]}, Axes -> True],
>>> Plot[Sin[x], {x, - Pi, Pi}]}]
>>>
>>> No wonder this sort of thing gives so much trouble!
>>>
>>> But a much simpler way to do the whole thing is to use the different
>>> paradigm that's supplied by David Park's Presentations application:
>>>
>>> Needs["Presentations`Master`"]
>>>
>>> points = RandomReal[{-1,1},{100,2}];
>>>
>>> Draw2D[{
>>> Draw[Sin[x],{x,-Pi,Pi}],
>>> {Red,Line[points]}
>>> },
>>> Axes->True]
>>>
>>> Notice that the Axes->True option is for the entire Draw2D expression;
>>> this means you'll get axes without any further ado no matter in what
>>> order you list the two objects, Draw[Sin[x]....] and  
>>> {Red,Line[points]}.
>>>
>>> I've deliberately pretty-printed both versions in order to emphasize  
>>> the
>>> structure of the overall expression.
>>>
>>> In the version done with Presentations, notice that all the different
>>> objects to be drawn (by the Draw2D) are "at the same level", one after
>>> the other, so that there's no need for wrapping the {Red,Line[points]
>>> expression with Graphics.
>>>
>>> With Presentations, moreover, you don't have to explicitly form pairs  
>>> of
>>> reals as coordinates of the points, but may instead form complex  
>>> numbers
>>> directly and plot a "complex line" whose vertices are the corresponding
>>> complex points:
>>>
>>> points = RandomComplex[{-1 - I, 1 + I}, 100];
>>> Draw2D[{Draw[Sin[x],{x,-Pi,Pi}],Red,ComplexLine[pts]},Axes->True]
>>>
>>>
>>> On 1/31/2010 7:53 AM, a boy wrote:
>>>> points = RandomReal[{-1, 1}, {100, 2}]
>>>> Graphics[{Red, Line[points], Plot[Sin[x], {x, -10 Pi, 10 Pi}]},
>>>> Axes -> True]
>>>
>>
>>
>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: Re: Numerical Problem
  • Next by Date: Mathematica 6.01 does not know one can not divide by 0??
  • Previous by thread: Re: Export[..., ImageResolution, ... ImageSize]
  • Next by thread: Re: How to combine graphics