9
$\begingroup$

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}]
$\endgroup$
1
  • 2
    $\begingroup$ ListPlot[{#} &@data, PlotMarkers -> {Automatic, Medium}, Epilog -> (Text[First@#, Rest@## + {0, .25}] & /@ (Transpose[{#, Range@Length@#, data}] &@elements))] $\endgroup$ Commented Apr 7, 2014 at 6:56

5 Answers 5

6
$\begingroup$
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.

$\endgroup$
16
$\begingroup$

Here is an illustration using Labeled that shows automatic placement:

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

enter image description here

$\endgroup$
6
  • $\begingroup$ It looks like Labeled in the first example positions the labels to avoid collisions. I didn't know it did that. $\endgroup$ Commented Oct 19, 2014 at 19:09
  • $\begingroup$ @Simon I think that was one of the new-in-v10 features. I'll see if I can find a reference. $\endgroup$
    – Mr.Wizard
    Commented Oct 19, 2014 at 19:10
  • $\begingroup$ @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. $\endgroup$
    – Mr.Wizard
    Commented Oct 19, 2014 at 19:12
  • $\begingroup$ @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. $\endgroup$
    – kglr
    Commented Oct 19, 2014 at 19:24
  • $\begingroup$ @kguler Okay, I kept only that part of my answer. $\endgroup$
    – Mr.Wizard
    Commented Oct 19, 2014 at 19:32
14
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ qwrety, +1, but if Cr value were a little higher (eg maybe with different data), it would be next to Mn and read CrMn. $\endgroup$ Commented Oct 19, 2014 at 17:05
5
$\begingroup$
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}]
$\endgroup$
2
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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