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.
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}}
DateListPlot[data, InterpolationOrder -> 0, Filling -> Bottom,
FillingStyle -> Pink]
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"}]
Altenatively, specify your own bin delimiters:
binlims = Append[ wd["InputData"],
DatePlus[wd["InputData"][[-1]], {1, "Month"}]];
DateHistogram[wd, {binlims}]
2. You can use DateListStepPlot
:
DateListStepPlot[data, Filling -> Axis]
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}]
Answered by kglr on June 7, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP