-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchart.py
More file actions
33 lines (27 loc) · 1 KB
/
chart.py
File metadata and controls
33 lines (27 loc) · 1 KB
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
# Draw a bar chart of frequency statistics of plant-disease relationships
import pandas as pd
import matplotlib.pyplot as plt
import openpyxl
# Read Excel data
df = pd.read_excel("gold-standard-corpus.xlsx")
label_list = list(df['relation'].value_counts().index)
num_list = df['relation'].value_counts().tolist()
plt.rcParams['font.family'] = ['DejaVu Sans']
# Drawing bar charts with Matplotlib
x = range(len(num_list))
rects = plt.bar(x=x, height=num_list, width=0.6, color='blue', label="Frequency")
plt.ylim(0, 800) # y-axis range
plt.ylabel("Quantity")
plt.xticks([index + 0.1 for index in x], label_list)
plt.xticks(rotation=10) # x-axis labels rotated 45 degrees
plt.xlabel("Entities Relationships")
plt.title("Plant Disease Relationship Frequency Statistics")
plt.legend()
# Text description
for rect in rects:
height = rect.get_height()
plt.text(rect.get_x() + rect.get_width() / 2, height + 1, str(height), ha="center", va="bottom")
# Show Chart
# plt.show()
# Save Chart
plt.savefig('bar_chart.png')