Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like to make a scatter plot where each element corresponds to a certain energy. Each plot marker should have its corresponding element next to it. IE. The data point at -1.16187 should have "Sc" next to it. How can this be done?

data = {-1.16187, -1.48643, -3.31205, -0.541609, -4.18021, -4.79914,
   -4.3378, -3.10561, -0.968065, -1.1105, -8.40646, 0, -1.61386,
   -1.12215, -1.55604, -1.40126, -1.23439, -1.01761, -1.31265, -1.63032,
   -1.4456, -0.944587, -1.45256, -1.49496, -1.38007, -1.12108, -1.04517};

elements = {"Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Y",
   "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Hf", "Ta", "W",
   "Re", "Os", "Ir", "Pt", "Au"};

p1 = ListPlot[{#} &@data, FillingStyle -> Thick,
  PlotMarkers -> {Automatic, Medium}]
share|improve this question
2  
ListPlot[{#} &@data, PlotMarkers -> {Automatic, Medium}, Epilog -> (Text[First@#, Rest@## + {0, .25}] & /@ (Transpose[{#, Range@Length@#, data}] &@elements))] –  belisarius Apr 7 at 6:56

5 Answers 5

up vote 4 down vote accepted
dataPlot = ListPlot[data, PlotStyle -> PointSize -> Large, AxesOrigin -> {0, -9}, PlotRange -> {Automatic, {-9, 1}}];
labels = MapThread[Text[#1, {#2, #3 + 0.3}] &, {elements, Range[Length@data], data}];
Show[dataPlot, Graphics[labels]]

should do the job.

share|improve this answer

With some decoration :

With[{coord = MapIndexed[{#2[[1]], #1} &, data]}, 
   Graphics[{MapThread[Style[Text[#1, #2 + If[OddQ[#2[[1]]], {0, 2}, {0, -2}]],
       Black, 18, Italic] &, {elements, coord}], PointSize[Large], Gray, 
         Line[{#, # + If[OddQ[#[[1]]], {0, 1.4}, {0, -1.4}]}] & /@ coord, 
           Blue, Point@coord}, Axes -> {None, True}, AxesOrigin -> {0, -9}, 
             ImageSize -> 500]]

enter image description here

share|improve this answer
    
qwrety, +1, but if Cr value were a little higher (eg maybe with different data), it would be next to Mn and read CrMn. –  alancalvitti Oct 19 at 17:05
ListPlot[List /@ (Labeled[#, Style[#2, 12, "Panel"], Top] & @@@ 
    Transpose[{Transpose[{Range@Length@data, data}], elements}]),
 Filling -> Axis, FillingStyle -> Automatic,
 PlotStyle -> ColorData[1, "ColorList"], 
 BaseStyle -> Directive[{Opacity[1.], Thickness[.02], PointSize[.025]}],
 ImageSize -> 500, ImagePadding -> 25, PlotRangeClipping -> False]

enter image description here


Original post:

ListPlot[Thread@Labeled[data, elements, Right], Filling -> Axis, 
 FillingStyle -> Thick, PlotMarkers -> {Automatic, Medium}]
share|improve this answer

Here is an illustration using Labeled that shows automatic placement:

ListPlot[
  MapThread[Labeled, {data, elements}],
  PlotStyle -> PointSize[0.015]
]

enter image description here

share|improve this answer
    
It looks like Labeled in the first example positions the labels to avoid collisions. I didn't know it did that. –  Simon Woods Oct 19 at 19:09
    
@Simon I think that was one of the new-in-v10 features. I'll see if I can find a reference. –  Mr.Wizard Oct 19 at 19:10
    
@kguler I already voted for your pretty answer. I merely wanted to give a simpler example. I feel our present posts are complementary, but if you wish to include your original code (which I didn't see) in your present post I can delete this one. –  Mr.Wizard Oct 19 at 19:12
    
@Mr.Wizard, i updated to include the original answer. By the way, I am glad you posted this answer, because, otherwise, i don't think i would ever notice the collision avoidance Simon noticed. –  kguler Oct 19 at 19:24
    
@kguler Okay, I kept only that part of my answer. –  Mr.Wizard Oct 19 at 19:32

May I cheat by deleting "ZR" and its associated 0 value and plotting with positive Y-ticks?

BarChart[-data,
 BarOrigin -> Top,
 BarSpacing -> 0.5,
 ChartElementFunction -> "GradientScaleRectangle",
 ChartLabels -> Placed[elements, Above],
 Frame -> True,
 GridLines -> Automatic,
 ImageSize -> 500,
 Method -> {"GridLinesInFront" -> True},
 PlotRangePadding -> {{None, 0.5}, {None, 0.3}},
 ScalingFunctions -> "Log"]

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.