-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.py
81 lines (67 loc) · 3.23 KB
/
generator.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
## Author: ssmtariq
## Copyright: Copyright 2023
# Load data from .txt files
data1 = np.loadtxt('data1.txt')
data2 = np.loadtxt('data2.txt')
# Fit kernel density estimates
kde1 = sns.kdeplot(data1, cumulative=True, linewidth=9, label='Data 1', color='red')
kde2 = sns.kdeplot(data2, cumulative=True, linewidth=9, label='Data 2', color='green')
######### Option-1: Add vertical & horizontal line without data label ############
# Compute 99th percentile
percentile_99_data1 = np.percentile(data1, 99)
percentile_99_data2 = np.percentile(data2, 99)
# Add vertical lines for 99th percentile
plt.axvline(percentile_99_data1, color='red', linestyle='--', linewidth=6)
plt.axvline(percentile_99_data2, color='green', linestyle='--', linewidth=6)
# Add horizontal lines for 99th percentile
plt.axhline(0.99, color='red', linestyle='--', linewidth=6)
plt.axhline(0.99, color='green', linestyle='--', linewidth=6)
############################ Option-1 End ####################################
######### Option-2: Add 95th percentile data label on horizontal line ############
# # Compute and plot 95th percentile for data 1
# pct95_1 = np.percentile(data1, 95)
# plt.axhline(y=0.95, linestyle='--', color='red', linewidth=2)
# plt.axvline(x=pct95_1, linestyle='--', color='red', linewidth=2)
# plt.text(pct95_1 + 2, 0.95, f'{pct95_1:.2f} ms', fontsize=14, color='red')
#
# # Compute and plot 95th percentile for data 2
# pct95_2 = np.percentile(data2, 95)
# plt.axhline(y=0.95, linestyle='--', color='green', linewidth=2)
# plt.axvline(x=pct95_2, linestyle='--', color='green', linewidth=2)
# plt.text(pct95_2 + 2, 0.95, f'{pct95_2:.2f} ms', fontsize=14, color='green')
############################ Option-2 End ####################################
######### Option-3: Add 95th percentile data label on vertical line ############
# # Calculate 95th percentile values for both data sets
# pct_95_data1 = np.percentile(data1, 95)
# pct_95_data2 = np.percentile(data2, 95)
#
# # Add vertical line for 95th percentile of Data 1
# plt.axvline(pct_95_data1, color='red', linestyle='--', linewidth=2)
# plt.text(pct_95_data1, 0.5, f"{pct_95_data1:.2f}", fontsize=14, color='red')
#
# # Add vertical line for 95th percentile of Data 2
# plt.axvline(pct_95_data2, color='green', linestyle='--', linewidth=2)
# plt.text(pct_95_data2, 0.5, f"{pct_95_data2:.2f}", fontsize=14, color='green')
#
# # Add horizontal line for 95th percentile
# plt.axhline(0.95, color='black', linestyle='--', linewidth=2)
############################ Option-3 End ####################################
# Add labels and title
plt.xlabel('Latency(ms)', fontsize=48, labelpad=20)
plt.ylabel('CDF', fontsize=48, labelpad=10)
plt.title('Thingsboard', fontsize=52, pad=20)
# Add some space before xlabel
plt.subplots_adjust(bottom=0.16)
# Set custom legend colors
legend_handles = [Line2D([0], [0], color='red', linewidth=9),
Line2D([0], [0], color='green', linewidth=9)]
plt.legend(legend_handles, ['Original Code', 'Optimized Code'], fontsize=36, loc='lower right')
# Increase x and y tick label font size
plt.tick_params(axis='x', labelsize=36)
plt.tick_params(axis='y', labelsize=36)
# Display the plot
plt.show()