Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to find the Sun's nearest neighbor star using Mathematica? I tried enter image description here

but it didn't work

share|improve this question
up vote 32 down vote accepted
  EntityClass["Star", "StarNearest10"], {"Name", 
   "DistanceFromSun"}], #1[[2]] < #2[[2]] &]

(*{{"Proxima Centauri",   Quantity[4.2181,  "LightYears"]}, 
   {"Rigel Kentaurus A",  Quantity[4.38982, "LightYears"]}, 
   {"Rigel Kentaurus B",  Quantity[4.4001,  "LightYears"]}, 
   {"Barnard's Star",     Quantity[5.9339,  "LightYears"]}, 
   {"Wolf 359",           Quantity[7.78813, "LightYears"]}, 
   {"Lalande 21185",      Quantity[8.30217, "LightYears"]}, 
   {"Luyten 726-8 B",     Quantity[8.5573,  "LightYears"]}, 
   {"Luyten 726-8 A",     Quantity[8.5573,  "LightYears"]}, 
   {"Sirius",             Quantity[8.59093, "LightYears"]}*)

 Association[(a[[#, 1]] -> a[[#, 2]]) & /@ Range@Length@a], 
 DateFunction -> (DatePlus[DateObject[Round[#*365*24*60*60, 1]], 
     Quantity[-1900, "year"]] &), FrameLabel -> "Light Years", 
 PlotLabel -> "Distance from Sun"]

Mathematica graphics

share|improve this answer
Nice alternative use of TimelinePlot! – 2012rcampion Mar 21 at 3:51
Or using SortBy: a = Rest@SortBy[StarData[EntityClass["Star", "StarNearest10"], {"Name", "DistanceFromSun"}], Last] – Bob Hanlon Mar 21 at 4:09
Clever use of DateFunction. Is this the best idiom to make a timeline-like graphic whose axis is not time? – ConvexMartian Mar 26 at 13:49

Your Answer


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.