I scraped some webpage, get a dictionary of date versus number of mentions. Here is the code:
import matplotlib.pyplot as plt
def sortdict(d):
for key in sorted(d): yield d[key]
counter1={'2018-02-01': 22, '2018-01-31': 19,
'2018-01-30': 10, '2018-01-29': 5, '2018-01-27': 4,
'2018-01-28': 3, '2018-01-25': 3, '2018-01-23': 3, '2018-01-26': 3,
'2018-01-24': 2, '2018-01-01': 2, '2018-01-15': 2, '2018-01-12': 2,
'2018-01-09': 1, '2017-12-18': 1, '2017-12-26': 1, '2018-01-11': 1,
'2018-01-13': 1, '2017-11-28': 1, '2017-12-21': 1, '2017-12-22': 1,
'2017-02-09': 1, '2018-01-04': 1, '2017-01-17': 1, '2017-03-02': 1,
'2018-01-08': 1, '2017-12-09': 1, '2017-12-24': 1, '2017-02-20': 1,
'2018-01-14': 1, '2018-01-21': 1, '2017-12-28': 1, '2017-12-11': 1}
x_labels = [] #create an empty list to store the labels#for key in counter.keys():
# x_labels.append(key)
fig, ax = plt.subplots()
lists = sorted(counter1.items()) # sorted by key, return a list of tuplesprint(lists)
x, y = zip(*lists)
print(x)
print(y)
# unpack a list of pairs into two tuplesplt.scatter(x, y)
plt.xticks( range(len(x)), x, rotation=90,fontsize=5 )
plt.show()
results:
No comments:
Post a Comment