forked from Buroni/booksoup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_sentiment_timeline.py
35 lines (27 loc) · 944 Bytes
/
demo_sentiment_timeline.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import matplotlib as mpl
mpl.use('TkAgg')
from booksoup import BookSoup
import numpy as np
import matplotlib.pyplot as plt
times = []
objects = []
vals = []
# Enter the path to the top level of your facebook data folder below.
me = BookSoup("facebook-data")
# Enter the name of the conversation or the numerical ID below.
conversation = me.load_conversation(104)
for participant in conversation.participants:
timeline = conversation.sentiment_timeline(participant)
sorted_keys = sorted(timeline.keys())
times.append(timeline)
objects.append(sorted_keys)
vals.append([timeline[t] for t in sorted_keys])
y_pos = np.arange(len(objects[0]))
for i,v in enumerate(vals):
plt.plot(y_pos, v, alpha=0.5, label=conversation.participants[i])
plt.xticks(y_pos, objects[0])
plt.ylabel('Average Sentiment')
plt.title('Sentiment over time with ' + conversation.name)
plt.xticks(fontsize=8, rotation=90)
plt.legend()
plt.show()