correlation.py 1.73 KB
Newer Older
1
2
3
4
5
import math
import matplotlib.pyplot as plt
from xlap.analyse.util import extract_durations


6
7
8
9
10
11
12
13
14
15
16
17
18
19
def corr(df, duration, grid=False, ax=None, color="black", marker="+"):
    df.plot.scatter(ax=ax,
                    y="EndToEnd_D",
                    x=duration,
                    grid=grid,
                    loglog=True,
                    marker=marker,
                    color=color)

def corr_multi(dfs, duration, **kwargs):
    names = []
    for df in dfs:
        names.append(df.name)

20
21
    colors = ["green","blue","orange","purple","red","pink"]
    markers = ["v", "^", ">", "<", "+"]
22
23
24
25
26
27
28
29
    for idf, df in enumerate(dfs):
        corr(df, duration, color=colors[idf % len(colors)],
             marker=markers[idf % len(markers)], **kwargs)
    if len(names) > 1:
        kwargs["ax"].legend(names)
    kwargs["ax"].set_xlabel("{} [us]".format(duration))


30
def multi_correlation(dfs, config, export=False, file_name="MultiCorrelation.pdf"):
31
32
33
    durations = [x + "_D" for x in extract_durations(config)]
    durations.remove("EndToEnd_D")

34
    cols = 2
35
    rows = int(math.ceil(len(durations) / cols))
36
    items = len(durations)
37
    fig, axes = plt.subplots(nrows=rows, ncols=cols)
38
39
40
41
42
43
44
45
46
    fig.set_size_inches(5.5 * cols, 5.5 * rows, forward=True)


    for idx, duration in enumerate(durations):
        if items > cols:
            ax = axes[idx // cols, idx % cols]
        else:
            ax = axes[idx]
        corr_multi(dfs, duration, grid=True, ax=ax)
47

48
    plt.subplots_adjust(wspace=0.3,hspace=0.3)
49
50
51
    if export and file_name is not None:
        fig.savefig(file_name)
    plt.tight_layout()
52
    plt.show()
53
54
55

def correlation(df, config, export=False, file_name="SingleCorrelation.pdf"):
    return multi_correlation([df], config, export, file_name)