Best way of visualizing occurrences in time intervals

Viewed 105

Suppose the data of occurrence of a phenomenon is given as follows (0,1,2) and one wants to visualize the accumulated number of occurrence for each minute of a day. I have the following code to simulate that:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime
dtindex = pd.date_range(start='1/1/2018', end='1/10/2018', freq='min')
np.random.seed(0)
occurrence = np.random.randint(0, 3, len(dtindex))
df = pd.DataFrame({'data': occurrence }, index=dtindex)
df['time'] = df.index.time
df['time'] = df['time'].apply(lambda x: x.strftime("%H:%M"))
df.head()
    data    time
2018-01-01 00:00:00 0   00:00
2018-01-01 00:01:00 1   00:01
2018-01-01 00:02:00 0   00:02
2018-01-01 00:03:00 1   00:03
2018-01-01 00:04:00 1   00:04
counts = df.groupby('time').agg('sum')
counts.head()
    data
time    
00:00   9
00:01   7
00:02   9
00:03   9
00:04   9
df.groupby('time').agg('sum').plot()
plt.show()

enter image description here

Questions:

How can I plot the above in the following ways:

  1. (Color map) Scatter plot that shows the higher number with warmer color

  2. (Bubble size) Scatter plot that shows higher values with larger bubble size

0 Answers
Related