MathGroup Archive 2007

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

Search the Archive

Re: Plotting Points with Labels

  • To: mathgroup at
  • Subject: [mg83434] Re: Plotting Points with Labels
  • From: Albert <awnl at>
  • Date: Tue, 20 Nov 2007 03:54:39 -0500 (EST)
  • References: <fhrs0c$5i4$>

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

pntdata = {{0, 0, 100.01}, {2, 2, 350.4}, {4, 5, 380.5}};
shiftText = 0.8;

labeledpoint = Function[{x, y, dose},{
    Point[{x, y}],
        StringJoin["dose = ", ToString[Round[dose]], " cGy"],
        {x + shiftText, y}
      Bold, 12, Black

   {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 :-)


  • Prev by Date: Re: addons in Mathematica 6???
  • Next by Date: Matching string in Mathematica
  • Previous by thread: Re: Plotting Points with Labels
  • Next by thread: Re: Plotting Points with Labels