TransWikia.com

DateListPlot to DateListHistogram

Mathematica Asked by Z Ming Ma on June 7, 2021

I would appreciate help in easily converting a DateListPlot command into a DateListHistogram command. In principle, given the List, whether a plot where each point is represented by a point as versus a horizontal bar for a histogram is just a question of visual representation. I would appreciate a tip on how this can be realized in Mathematica.

2 Answers

data = {{DateObject[{2016, 10, 1}, "Day", "Gregorian", -5.`], 
    10}, {DateObject[{2016, 10, 15}, "Day", "Gregorian", -5.`], 
    17}, {DateObject[{2016, 10, 30}, "Day", "Gregorian", -5.`], 
    15}, {DateObject[{2016, 11, 20}, "Day", "Gregorian", -5.`], 20}}

enter image description here

DateListPlot[data, InterpolationOrder -> 0, Filling -> Bottom, 
 FillingStyle -> Pink]

enter image description here

It seems to represent differently the last day though...

Answered by chris on June 7, 2021

Using data from chris's answer:

data = {{DateObject[{2016, 10, 1}, "Day", "Gregorian", -5.`], 
   10}, {DateObject[{2016, 10, 15}, "Day", "Gregorian", -5.`], 
   17}, {DateObject[{2016, 10, 30}, "Day", "Gregorian", -5.`], 
   15}, {DateObject[{2016, 11, 20}, "Day", "Gregorian", -5.`], 
   20}}; 

1. You can create a WeightedData object from data and use it with DateHistogram:

wd = WeightedData @@ Transpose[data];

DateHistogram[wd, {15, "Day"}]

enter image description here

Altenatively, specify your own bin delimiters:

binlims = Append[ wd["InputData"], 
   DatePlus[wd["InputData"][[-1]], {1, "Month"}]];

DateHistogram[wd, {binlims}]

enter image description here

2. You can use DateListStepPlot:

DateListStepPlot[data, Filling -> Axis]

enter image description here

Use the second argument to specify the steps:

Column[DateListStepPlot[data, #, Filling -> Axis, 
    PlotLabel -> Style[#, 16], ImageSize -> Large, AspectRatio -> 1/3,
     PlotRange -> {{"Sep 1, 2016", "Dec 15, 2016"}, All}] & /@
  {Center, Left, Right}]

enter image description here

Answered by kglr on June 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP