Plotting a cumulative graph of python datetimes -
Say I have a list of datetimes, and we know that the timing of each time to be a record time of an event.
Is it possible to graph the frequency of this occurring event in time, it is possible in matplotlib, to show this data in a cumulative graph (so that each point equals all the points that were before it or More than that), the list without pre-processing it? ("Date": 1998, "Month": 12, "Date": 15, "Events": 92}
and then Generate a graph from this list?
This should work for you:
counts = arange ( 0, lane (list_of_dates)) plot (list_of_dates, counts)
You definitely want to graph any general option of plot
calls the way you want You can send it to see it. (I would suggest that matplotlib is very efficient in dealing with the date and time.)
There will be another option - one of the options is 'Cumulative = True' which can be useful if you can create a cumulative histogram Which shows the number of events occurring according to any given date:
matplotlib.dates import date from 2num hist (date2num (list_of_dates) to pipette import from hist, cumulative = true) < / Code>
But it once produced a chart, which is for you Aap can not be anything, and in any case the date labels on the display of the horizontal axis probably need something possibly bad.
edit : I understand what exactly you want, a point (or bar) per date, as well as the related Wi-Mn number till that date (and In this case, I suggest doing something like this:
grouped_data = [[D, lane (list)]] D For, in itertools.groupby (list_of_dates, lambda k: K.date ())] dates, calculation = grouped_dates.manager () calculation = calculations. What type of data are you searching for: (step, date, count)
by group
itertools
Only one instance of the date, with all the datetime objects that are on that date As Johnny has suggested in the comments, the
step
function will give a graph that the incidents have happened every day, so I use that code to plot
(Hat tip for EOL to remind me of cumsum
)
If you want a point every day, even if any incident happened that day Whether or not you have to change the above code a bit:
I do not think that actually a difference to the plot created by the step
function Will fall.
Comments
Post a Comment