MathGroup Archive 2007

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

Search the Archive

Re: Plotting Points with Labels

  • To: mathgroup at smc.vnet.net
  • Subject: [mg83522] Re: Plotting Points with Labels
  • From: sdw <nospam.warwick at jps.net>
  • Date: Thu, 22 Nov 2007 04:44:16 -0500 (EST)
  • References: <fhrs0c$5i4$1@smc.vnet.net> <fhu84a$7hq$1@smc.vnet.net>

slight improvement - need to make sure text is left justified relative 
to insertion point ..  add the {-1,0} to the text specification

labeledpoint =
   Function[{x, y, dose}, {Point[{x, y}],
     Style[Text[
       StringJoin["dose = ", ToString[Round[dose]],
        " cGy"], {x + shiftText, y}, {-1, 0}], Bold, 12, Black]}];




Albert wrote:
> JOHN ERB wrote:
>> The code below plots "pntdata" labeling the points, where the data
>>   represents the x and y coordinates, and the value at that point
>>   {{x1,y1,value1}, ... , {xN,yN,valueN}};
>>    
>>   The labels are shifted to the right (+x direction) of the respective points
>>   by the value of "shiftText."
>>    
>>   Is there a better (or more succinct) way of doing this?
> 
> While succinct is usualy not what matters, code quality has many aspects
> and needs to be defined more precisely. The following changes are merely 
> a matter of taste...
> 
> That said, in this case I would get rid of the intermediate expression
> newdata which doesn't really make things simpler. Here I also would
> prefer the @@@ operator which is an Apply with level 1, since it saves
> you all these brackets. Then I wouldn't nest the pure function so deeply
> but rather define it seperatly. In real code I would also prefer named
> arguments in the pure function for readability and finally for the same
> reason I am fond of using line breaks to reflect the nesting of
> expressions that are longer than a line (the frontend does a good job on
> automatic indentation, I think). The code I would write could look like
> this:
> 
> pntdata = {{0, 0, 100.01}, {2, 2, 350.4}, {4, 5, 380.5}};
> shiftText = 0.8;
> 
> labeledpoint = Function[{x, y, dose},{
>     Point[{x, y}],
>     Style[
>       Text[
>         StringJoin["dose = ", ToString[Round[dose]], " cGy"],
>         {x + shiftText, y}
>       ],
>       Bold, 12, Black
>     ]
> }]
> 
> Graphics[
>    {Red, PointSize[0.02], labeledpoint @@@ pntdata},
>    Frame -> True
> ]
> 
> hope you'll like my taste, the code isn't more succinct than it was
> before, though :-)
> 
> albert
> 


  • Prev by Date: Re: StringInput Question
  • Next by Date: Re: Get list of function variables?
  • Previous by thread: Re: Plotting Points with Labels
  • Next by thread: ordered positions (OrderedPosition?)