# Use Combinations of Wrappers

Plotting the distance of planets from Earth over time involves distances with units, time series, and associations for keeping track of the data. All of these objects can be combined and then directly plotted to get a beautiful plot in a straightforward way.

Create a function that gives the distance of a planet from Earth on a given date.

 In[1]:= Xdistance[planet_, date_] := PlanetData[planet, EntityProperty["Planet", "DistanceFromEarth", {"Date" -> date}]]

Generate a time series of the distance of a planet from Earth over the year 2014. The distances are in astronomical units.

 In[2]:= XdistanceSeries[planet_] := TimeSeries[({#1, distance[planet, #1]} &) /@ DateRange[{2014, 1, 1}, {2014, 12, 31}, "Week"]]
 In[3]:= Xmars = distanceSeries["Mars"]
 Out[3]=
 In[4]:= Xmars[Now]
 Out[4]=

Store the distances for several planets in an association.

 In[5]:= Xplanets = AssociationMap[ distanceSeries, {"Mercury", "Venus", "Mars", "Jupiter", "Saturn"}]
 Out[5]=

Plot the distances using an automatically created legend to identify them.

 In[6]:= XDateListPlot[planets, PlotLegends -> "Expressions", FrameLabel -> Automatic, ImageSize -> 400]
 Out[6]=

## Mathematica

Questions? Comments? Contact a Wolfram expert »