Date and Time Visualization

MinHsuan Peng

Visualization Group
Wolfram

Data

time format

AbsoluteTime[]

AbsoluteTime[{1900,1,1}]

AbsoluteTime[{1899,1,1}]

DateList[]

DateString[]

DateString[{"DayName", "  ","Month","/","YearShort"}]

DateString[{"DayName","(", "Day",")","---","MonthName","<<<>>>","Year"}]

DateString[{"12/26/1980",{"Month","/","Day","/","Year"}}]

conversions

DateList["23 Nov, 1992"]

DateString[{1992,11,23,0,0,0.`}]

AbsoluteTime[DateList[]]

AbsoluteTime[DateString[]]

FinancialData

FinancialData["F"]

FinancialData["GE",{"March 10, 2005",{2005,3,15}}]

FinancialData["F","OHLCV",{{2014,1,1},{2014,1,5}}]

DateObject

DateObject[]

Now

Yesterday

Tomorrow

Today

LocalTime[]

DateList[Now]

DateString[Today]

AbsoluteTime[LocalTime[]]

DatedUnit

Quantity[1,DatedUnit["USDollars",1800]]

TimeSeries and TemporalData

data=FinancialData["F","OHLCV",{{2010,1,1},{2014,6,1}}];

Length[data]

ts=TimeSeries[data]

ts["Properties"]

CountryData["UK",{"GDP",{1970,2008}}]

DateListPlot

DateListPlot[Range[10],{2010,1,1},PlotMarkers->Automatic]

FinancialData["C",{{2010,1,1},{2010,1,30}}]

DateListPlot[%,PlotMarkers->Automatic]

MapAt[DateString[#,{"Year","/","MonthName","/","Day"}]&,FinancialData["C",{{2010,1,1},{2010,1,30}}],{All,1}]

DateListPlot[%,DateFunction->(DateList[{#,{"Year","/","MonthName","/","Day"}}]&),PlotMarkers->Automatic,PlotRange->All]

usdata=Table[Quantity[1,DatedUnit["USDollars",1800+i]],{i,1,214}];

usdata//Short

DateListPlot[usdata,{{1801,1,1},{2014,1,1}},GridLines->{None,{1}},PlotRange->All,FrameLabel->Automatic,FrameTicks->{{Automatic,{{1,Quantity[1,"USDollars"]}}},{Automatic,Automatic}}]

TimeSeries support

data=FinancialData["F","OHLC",{{2010,1,1},{2010,6,1}}];
ts=TimeSeries[data]

data[[1]]

DateListPlot[ts,PlotLegends->{"open","high","low","close"}]

AirPressureData

data=AirPressureData[(Entity["Taipei City", Entity["City",{"TaipeiCity","TaipeiCity","Taiwan"}], "Entity[\"City\", {\"TaipeiCity\", \"TaipeiCity\", \"Taiwan\"}]", "city"]),{DateObject[{2011,5,1}],DateObject[{2011,10,31}]}]

DateListPlot[data,GridLines->{{(DateObject["Tue 10 May 2011", DateObject[{2011,5,10}]]),(DateObject["Sat 28 May 2011", DateObject[{2011,5,28}]]),(DateObject["Sat 25 Jun 2011", DateObject[{2011,6,25}]]),(DateObject["Sat 6 Aug 2011", DateObject[{2011,8,6}]]),(DateObject["Tue 30 Aug 2011", DateObject[{2011,8,30}]])},None},
PlotRange->{{(DateObject["Tue 10 May 2011", DateObject[{2011,5,10}]]),(DateObject["Sat 10 Sep 2011", DateObject[{2011,9,10}]])},Automatic}]

DeviceReadTimeSeries

dev=DeviceOpen["RandomSignalDemo"];

devts=DeviceReadTimeSeries[dev,{10,0.05}]

DateListPlot[{devts,MovingMap[Mean,devts,{10,Right}]},PlotLegends->{"data","mean"}]

WeatherData

wts=WeatherData[Here,"MeanTemperature",{{2013,10,1},{2014,4,1},"Day"}]

mean=MeanFilter[wts,10]

DateListPlot[{wts,mean},PlotLegends->{"daily mean temperature","10 days mean"}]

SunPosition

sp=SunPosition[(Entity["Chicago", Entity["City",{"Chicago","Illinois","UnitedStates"}], "Entity[\"City\", {\"Chicago\", \"Illinois\", \"UnitedStates\"}]", "city"]),DateRange[(DateObject["Tue 1 Jan 2013 09:00", DateObject[{2013,1,1},TimeObject[{9}]]]),(DateObject["Tue 31 Dec 2013 09:00", DateObject[{2013,12,31},TimeObject[{9}]]]),10]]

DateListPlot[sp,PlotLegends->{"azimuth","altitude"},PlotTheme->{"Scientific","Presentation","Wide"}]

ListLinePlot[sp]

ListLinePlot[{sp["Values"],Labeled[sp[#],DateString[#,"MonthName"]]&/@DateRange[(DateObject["Tue 1 Jan 2013 09:00", DateObject[{2013,1,1},TimeObject[{9}]]]),(DateObject["Tue 31 Dec 2013 09:00", DateObject[{2013,12,31},TimeObject[{9}]]]),{1,"Month"}]},Joined->{True,False},ImageSize->450,PlotLabel->"analemma of the Sun",PlotTheme->{"Scientific","Presentation"},FrameLabel->{"azimuth","altitude"}]

Visualization

charting support

DatedUnit

usdata=Table[Quantity[1,DatedUnit["USDollars",1800+i]],{i,1,214}];

BarChart[usdata]

time stamps get ignored

ts=TimeSeries[RandomReal[1,{12,3}],{"Jan, 2013","Dec, 2013","Month"}]

BarChart[ts]

PieChart[ts,PlotTheme->"Minimal"]

BoxWhiskerChart

Brownian motion

ts=RandomFunction[WienerProcess[0,0.01],{0,200,1},10]

DateListPlot[ts]

BoxWhiskerChart[ts,Joined->True]

DistributionChart[ts]

Example: advertising and sales data

data=Import["/Users/minhsuanp/Documents/Wolfram/Charts/Talks/2014/advertising-and-sales-data-36-co.csv"];

data

data=data[[2;;-4]]

ndata=MapAt[(DateList[{#,{"Year","-","Month"}}]+{2000,0,0,0,0,0})&,data,{All,1}]

DateListPlot[Tooltip[data],DateFunction->((DateList[{#,{"Year","-","Month"}}]+{2000,0,0,0,0,0})&),PlotMarkers->Graphics[{{AbsolutePointSize[8],GrayLevel[1],Point[{0,0}]},AbsolutePointSize[6],Point[{0,0}]}]]

qd=TimeSeriesAggregate[ndata,{"Quarter",Center},Total]

DateListPlot[Partition[qd,4],PlotMarkers->Automatic,FrameTicks->{qd[[All,1]],Automatic},DateTicksFormat->{"Quarter", "/", "YearShort"},Filling->Axis,Joined->True]

ts=TimeSeries/@Partition[qd,4]

BarChart[ts,ChartLabels->{Placed[{2001,2002,2003},Above],Placed[ts[[1]]["Dates"],Automatic,DateString[#,"QuarterNameShort"]&]},BarSpacing->{None,1}]

BarChart[ts,ChartLayout->"Percentile",ChartLabels->{Placed[{2001,2002,2003},Axis],Placed[qd[[All,1]],Automatic,DateString[#,"QuarterNameShort"]&]},BarSpacing->{None,0.5}]

Application

Tohoku earthquake

GeoGraphics[{GeoMarker[{38.322,142.369}],Entity["Country","Japan"]}]

{GeoPosition[{43.358`,141.196`},ITRF00],GeoPosition[{42.0766`,144.423`},ITRF00],GeoPosition[{39.888`,145.258`},ITRF00],GeoPosition[{36.1119`,145.184`},ITRF00],GeoPosition[{33.4671`,143.195`},ITRF00],GeoPosition[{34.2712`,139.204`},ITRF00],GeoPosition[{37.6754`,136.263`},ITRF00],GeoPosition[{41.0245`,137.504`},ITRF00]}

ITRF00="ITRF00"

area=Polygon@{GeoPosition[{37.2065`,135.574`},ITRF00],GeoPosition[{35.7641`,137.611`},ITRF00],GeoPosition[{33.1307`,138.867`},ITRF00],GeoPosition[{31.6236`,142.329`},ITRF00],GeoPosition[{32.8924`,144.004`},ITRF00],GeoPosition[{35.004`,146.351`},ITRF00],GeoPosition[{37.6143`,146.941`},ITRF00],GeoPosition[{40.0875`,147.24`},ITRF00],GeoPosition[{43.4706`,147.942`},ITRF00],GeoPosition[{45.8686`,148.4`},ITRF00],GeoPosition[{46.0556`,143.381`},ITRF00],GeoPosition[{45.5483`,140.853`},ITRF00],GeoPosition[{43.2967`,138.73`},ITRF00],GeoPosition[{40.188`,136.47`},ITRF00]};

GeoGraphics[{GeoMarker[{38.322,142.369}],area}]

low magnitudes

eq=Values[EarthquakeData[area,{2,5},{{2005,1,1},{2014,9,20}}]];

Length[eq]

eq[[1]]

pos={#["Position"],#["Magnitude"]}&/@eq;

pos=SortBy[pos,Last];

Through[{Min,Max}[pos[[All,2]]]]

GeoGraphics[{GeoMarker[#[[1]],Graphics[{{FaceForm[Opacity[Rescale[#[[2]],{3,5},{0.3,0.8}]]],EdgeForm[Opacity[Rescale[#[[2]],{3,5},{0.1,0.4}]]],Disk[]}}],"Scale"->Offset[Rescale[10^#[[2]],10^{3,5},{2,8}]],"Color"->Hue[Rescale[#[[2]],{3,5},{0,1}]]]&/@pos,area,GeoMarker[{38.322,142.369},"Color"->Orange]}]

ts={#["Period"],#["Magnitude"]}&/@eq;

ts=TimeSeries[ts,TemporalRegularity->True]

DateListPlot[ts,Joined->False,Filling->Bottom]

nts=MeanFilter[MeanFilter[ts,5],5]

DateListPlot[nts,Joined->False,Filling->Bottom]

times=#["Period"]&/@eq;

Histogram[AbsoluteTime/@times,{60*60*24*30*2},ScalingFunctions->"Log",Ticks->{({#,DateString[#,{"Day","/","Month","/","YearShort"}]}&/@findDivisions[{#1,#2},10]&),Automatic}]

{t,c}=HistogramList[AbsoluteTime/@times,{60*60*24*30*2}]

ts=Transpose[{Rest[t],c}];

DateListLogPlot[ts,PlotRange->All]

wdata=WeightedData[AbsoluteTime[#["Period"]]&/@eq,10^#["Magnitude"]&/@eq]

Histogram[wdata,{60*60*24*30*2},ScalingFunctions->"Log",Ticks->{({#,DateString[#,{"Day","/","Month","/","YearShort"}]}&/@findDivisions[{#1,#2},6]&),Automatic}]

high magnitudes

heq=Values[EarthquakeData[area,5,{{2005,1,1},{2014,9,20}}]];

Length[heq]

pos={#["Position"],#["Magnitude"]}&/@heq;

pos=SortBy[pos,Last];

Through[{Min,Max}[pos[[All,2]]]]

GeoGraphics[{GeoMarker[#[[1]],Graphics[{{FaceForm[Opacity[Rescale[#[[2]],{5,9},{0.3,0.8}]]],EdgeForm[Opacity[Rescale[#[[2]],{5,9},{0.1,0.6}]]],Disk[]}}],"Scale"->Offset[Rescale[10^#[[2]],10^{5,9},{8,40}]],"Color"->Hue[Rescale[#[[2]],{5,9},{0,1}]]]&/@pos,area, GeoMarker[{38.322,142.369},"Color"->Orange]}]

hts={#["Period"],#["Magnitude"]}&/@heq;

hts=TimeSeries[hts,TemporalRegularity->True]

DateListPlot[hts,Joined->False,Filling->Bottom]

hnts=MeanFilter[MeanFilter[hts,5],5]

DateListPlot[hnts,Joined->False,Filling->Bottom,PlotRange->All]

DateListPlot[{nts,hnts},Joined->False,Filling->Bottom]

htimes=#["Period"]&/@heq;

Histogram[AbsoluteTime/@htimes,{60*60*24*30*2},ScalingFunctions->"Log",Ticks->{({#,DateString[#,{"Day","/","Month","/","YearShort"}]}&/@findDivisions[{#1,#2},6]&),Automatic}]

Histogram[AbsoluteTime/@times,{60*60*24*30*2},ScalingFunctions->"Log",Ticks->{({#,DateString[#,{"Day","/","Month","/","YearShort"}]}&/@findDivisions[{#1,#2},6]&),Automatic}]

whdata=WeightedData[AbsoluteTime[#["Period"]]&/@heq,10^#["Magnitude"]&/@heq]

Histogram[whdata,{"Raw",50},ScalingFunctions->"Log",Ticks->{({#,DateString[#,{"Day","/","Month","/","YearShort"}]}&/@findDivisions[{#1,#2},6]&),Automatic}]

energy=HistogramList[whdata,{"Raw",{2592000}}][[2]]+HistogramList[wdata,{"Raw",{2592000}}][[2]];

t=Rest[HistogramList[whdata,{"Raw",{2592000}}][[1]]];

DateListLogPlot[Transpose[{t,energy}],PlotRange->All,GridLines->{{{{2011,3,11},Directive[Thick,Red]}},None},FrameTicks->{{Automatic,Automatic},{Automatic,{{{2011,3,11},DateObject[{2011,3,11}]}}}}]

BubbleChart

eq=Values[EarthquakeData[area,6,{{2005,1,1},{2014,9,20}}]];

Length[eq]

eq[[1]]

ts={AbsoluteTime@#["Period"],#["Depth"],#["Magnitude"]}&/@eq;

BubbleChart[ts,ScalingFunctions->{None,"Reverse",{10^#&,Log10}},BubbleSizes->{0.05,0.4},FrameTicks->{{Automatic,Automatic},{({#,DateString[#,{"Month","/","Day","/","YearShort"}]}&/@FindDivisions[{#1,#2},6]&),{{AbsoluteTime[{2011,3,11}],DateString[{2011,3,11},{"Month","/","Day","/","YearShort"}]}}}},ColorFunction->((ColorData["TemperatureMap"][Abs@#3])&),ColorFunctionScaling->True,FrameLabel->Automatic,GridLines->{{AbsoluteTime[{2011,3,11}]},None}]

bs={Sequence@@(#["Position"][[1]]),#["Depth"],#["Magnitude"]}&/@eq;

BubbleChart3D[bs,ScalingFunctions->{None,None,"Reverse",{10^#&,Log10}},ColorFunction->((ColorData["TemperatureMap"][Abs@#4])&),ColorFunctionScaling->True,BubbleSizes->{0.01, 0.1},PlotTheme->{"Detail","Presentation"},AxesLabel->Automatic]

bsts=TimeSeries[{#["Period"],{Sequence@@(#["Position"][[1]]),#["Depth"],#["Magnitude"]}}&/@eq];

t=#["Period"]&/@eq;

Manipulate[
BubbleChart3D[MapThread[#->#2&,{bs,t}],ScalingFunctions->{None,None,"Reverse",{10^#&,Log10}},ColorFunction->((ColorData["TemperatureMap"][Abs@#4])&),ColorFunctionScaling->True,BubbleSizes->{0.01, 0.1},ChartBaseStyle->Opacity[0.5],PerformanceGoal->"Speed",PlotTheme->{"Detail","Presentation"},AxesLabel->Automatic,ChartElementFunction->(Dynamic[If[i>AbsoluteTime@First[Flatten[#3]],ChartElementData["Bubble3D"][##],{}]]&),PlotLabel->Dynamic[DateString[i,{"Month","/","Day","/","Year"}]]],{i,AbsoluteTime[t[[1]]],AbsoluteTime@t[[-1]],60*60*24},SaveDefinitions->True]

Indian Ocean & Sumatra earthquakes

GeoGraphics[{GeoMarker[{3.316,95.854}],GeoMarker[{-4.520,101.374}]},GeoRange->{{-10,20},{90,110}}]

ITRF00="ITRF00";

iarea=Polygon@{GeoPosition[{15.41`,91.842`},ITRF00],GeoPosition[{13.4455`,90.21`},ITRF00],GeoPosition[{9.87543`,90.2454`},ITRF00],GeoPosition[{3.96409`,90.7189`},ITRF00],GeoPosition[{-3.29745`,93.1855`},ITRF00],GeoPosition[{-6.43607`,98.8319`},ITRF00],GeoPosition[{-7.59207`,104.498`},ITRF00],GeoPosition[{-4.94464`,106.777`},ITRF00],GeoPosition[{-0.063188`,104.338`},ITRF00],GeoPosition[{3.66844`,100.265`},ITRF00],GeoPosition[{8.09615`,97.0886`},ITRF00],GeoPosition[{12.0213`,95.5237`},ITRF00],GeoPosition[{15.6604`,94.0573`},ITRF00]}

GeoGraphics[{GeoMarker[{3.316,95.854}],GeoMarker[{-4.520,101.374}],iarea}]

low magnitudes

eq=Values[EarthquakeData[iarea,{2,5},{{1990,1,1},{2008,12,31}}]];

Length[eq]

ts={#["Period"],#["Magnitude"]}&/@eq;

ts=TimeSeries[ts,TemporalRegularity->True]

nts=MeanFilter[MeanFilter[ts,5],5]

DateListPlot[ts,Joined->False,Filling->Bottom,PlotRange->All,AspectRatio->1/4]

DateListPlot[nts,Joined->False,Filling->Bottom,PlotRange->All]

times=#["Period"]&/@eq;

Histogram[AbsoluteTime/@times,{"Raw",100},Ticks->{({#,DateString[#,{"Day","/","Month","/","YearShort"}]}&/@System`FindDivisions[{#1,#2},6]&),Automatic}]

wdata=WeightedData[AbsoluteTime[#["Period"]]&/@eq,10^#["Magnitude"]&/@eq]

Histogram[wdata,{"Raw",50},Ticks->{({#,DateString[#,{"Day","/","Month","/","YearShort"}]}&/@System`FindDivisions[{#1,#2},6]&),Automatic}]

high magnitudes

ITRF00="ITRF00";

heq=Values[EarthquakeData[iarea,5,{{1990,1,1},{2008,12,31}}]];

Length[heq]

hts={#["Period"],#["Magnitude"]}&/@heq;

hts=TimeSeries[hts,TemporalRegularity->True]

hnts=MeanFilter[MeanFilter[hts,5],5]

hnts=FinancialIndicator["EMA"][hts]

DateListPlot[hts,Joined->False,Filling->Bottom,PlotRange->All]

DateListPlot[hnts,Joined->False,Filling->Bottom,PlotRange->All]

DateListPlot[{nts,hnts},Joined->False,Filling->Bottom,PlotRange->All]

htimes=#["Period"]&/@heq;

Histogram[AbsoluteTime/@htimes,{"Raw",50},(*ScalingFunctions->"Log",*)Ticks->{({#,DateString[#,{"Day","/","Month","/","YearShort"}]}&/@findDivisions[{#1,#2},6]&),Automatic}]

Histogram[AbsoluteTime/@times,{"Raw",50},Ticks->{({#,DateString[#,{"Day","/","Month","/","YearShort"}]}&/@System`FindDivisions[{#1,#2},6]&),Automatic}]

whdata=WeightedData[AbsoluteTime[#["Period"]]&/@heq,10^#["Magnitude"]&/@heq]

Histogram[whdata,{"Raw",50},Ticks->{({#,DateString[#,{"Day","/","Month","/","YearShort"}]}&/@System`FindDivisions[{#1,#2},6]&),Automatic}]

energy=HistogramList[whdata,{"Raw",50}][[2]]+HistogramList[wdata,{"Raw",50}][[2]]

t=Rest[HistogramList[whdata,{"Raw",50}][[1]]]

DateListLogPlot[Transpose[{t,energy}],PlotRange->All,ImageSize->700,AspectRatio->1/2,GridLines->{{{{2004,12,31},Directive[Thick,Red]},{{2007,9,12},Directive[Thick,Red]}},None}]

Thank you

ClearAll[findDivisions];
Attributes[findDivisions]=NHoldAll;
findDivisions[a___]:=FindDivisions[a]

$PlotTheme={"Presentation","Wide"}

$PlotTheme={}