-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisualisation.py
60 lines (51 loc) · 1.98 KB
/
visualisation.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import matplotlib.pyplot as plt
from nltk.corpus import stopwords
from wordcloud import WordCloud, STOPWORDS
import matplotlib.pyplot as plt
import numpy as np
german_stopwords = set(stopwords.words('german'))
def plot_data(df, class_name):
ax = df[class_name].value_counts().plot(kind='bar',
figsize=(12, 8),
title="Class Distribution")
total = 0
for p in ax.patches:
total += p.get_height()
for p in ax.patches:
ax.annotate(np.round(p.get_height(), decimals=2), (p.get_x() + p.get_width() / 2, p.get_height() / 2),
ha='center', va='center', xytext=(0, 10), textcoords='offset points',
bbox=dict(facecolor='yellow', alpha=0.5))
ax.annotate(str(np.round(p.get_height() / total * 100, decimals=2)) + "%",
(p.get_x() + p.get_width() / 2, p.get_height() / 2),
ha='center', va='center', xytext=(0, -20), textcoords='offset points',
bbox=dict(facecolor='gray', alpha=0.5))
def plot_word_cloud(df):
text = df.tweet.values
wordcloud = WordCloud(
width = 3000,
height = 2000,
background_color = 'black',
stopwords = german_stopwords).generate(str(text))
fig = plt.figure(
figsize = (40, 30),
facecolor = 'k',
edgecolor = 'k')
plt.imshow(wordcloud, interpolation = 'bilinear')
plt.axis('off')
plt.tight_layout(pad=0)
plt.show()
def plot_hindi_word_cloud(df):
text = df.text.values
wordcloud = WordCloud( font_path='font/ArialUnicodeMS.ttf',
width = 3000,
height = 2000,
background_color = 'black',
stopwords = STOPWORDS).generate(str(text))
fig = plt.figure(
figsize = (40, 30),
facecolor = 'k',
edgecolor = 'k')
plt.imshow(wordcloud, interpolation = 'bilinear')
plt.axis('off')
plt.tight_layout(pad=0)
plt.show()