2023-10-20 07:57:43 +00:00
import matplotlib . pyplot as plt
import scienceplots
import numpy as np
from analyze import load
latencies = [ load ( " raw/latency_10kb.txt " , " arrival_diff= " ) ,
2024-02-05 08:47:27 +00:00
load ( " raw/latency_scenario2_10kb.txt " , " arrival_diff= " ) ,
2023-10-20 07:57:43 +00:00
load ( " raw/latency_100kb.txt " , " arrival_diff= " ) ,
2024-02-05 08:47:27 +00:00
load ( " raw/latency_scenario2_100kb.txt " , " arrival_diff= " ) ,
#load("raw/latency_500kb.txt", "arrival_diff="),
#load("raw/latency_scenario2_500kb.txt", "arrival_diff=")
]
2023-10-20 07:57:43 +00:00
with plt . style . context ( [ ' science ' , ' ieee ' ] ) :
fig , ax = plt . subplots ( )
bp = ax . boxplot ( latencies , notch = True , vert = True , patch_artist = True ,
showfliers = True , whis = 100000000000 )
2024-02-05 08:47:27 +00:00
for patch , color in zip ( bp [ ' boxes ' ] , [ ' red ' , ' blue ' , ' gold ' , ' yellowgreen ' ] ) :
2023-10-20 07:57:43 +00:00
patch . set_facecolor ( color )
2024-02-05 08:47:27 +00:00
ax . set ( title = " Message latencies distribution \n D=6 vs D=3 nodes=1000 samples= " + str ( latencies [ 1 ] . size ) , xlabel = ' Scenario ' , ylabel = ' Message propagation time (ms) ' )
2023-10-20 07:57:43 +00:00
ax . grid ( linestyle = ' - ' )
my_legend = [ ]
2024-02-05 08:47:27 +00:00
for msg_size in [ 10 , 100 ] :
for d in [ 6 , 3 ] :
my_legend . append ( " Message size: " + str ( msg_size ) + " kB " + " D= " + str ( d ) )
2023-10-20 07:57:43 +00:00
ax . legend ( [ bp [ " boxes " ] [ i ] for i in range ( len ( my_legend ) ) ] , my_legend , loc = ' upper left ' , fontsize = 5 )
for i , line in enumerate ( bp [ ' medians ' ] ) :
x , y = line . get_xydata ( ) [ 1 ]
text = r ' $ \ mu =$ ' + ' {:.0f} ms \n ' . format ( latencies [ i ] . mean ( axis = 0 ) ) + r ' $ p_ {95} = $ ' + ' {:.0f} ms ' . format ( np . percentile ( latencies [ i ] , 95 ) )
ax . annotate ( text , xy = ( x + 0.1 , y ) , fontsize = 6 )
fig . set_size_inches ( 4 , 3 )
2024-02-05 08:47:27 +00:00
fig . savefig ( ' latencies_d6_vs_d3.svg ' , dpi = 600 )