예제 #1
0
파일: plotlib.py 프로젝트: kemas/ns3
def loadarg(lsarg):
    ds = []
    for i in range(len(lsarg)):
        func = lsarg[i]['func'][0]

        step = p.STEP
        argstep = getargval(lsarg[i], '-j')
        if argstep:
            step = int(argstep[0])

        for finjson in lsarg[i]['files']:
            f = open(finjson)
            try:
                data = json.load(f)

                p.loaddata(ds, func, data, finjson, step)
            finally:
                f.close()

        xlim = getargval(lsarg[i], '-xlim')
        ylim = getargval(lsarg[i], '-ylim')

        plotfile = getargval(lsarg[i], '-v', [None])[0]

        axisfsize = getargval(lsarg[i], '-axisfsize', ['medium'])[0]
        try:
            axisfsize = int(axisfsize)
        except:
            pass

    return ds
예제 #2
0
파일: plotsfexprand.py 프로젝트: kemas/ns3
def main(argv):
    lsarg = []


    lsarg.append({'func':['-li'], 'files':['simdata/svcsimn_10k_10k_d2_a7_i10_avg1_8.json'], '-m':['reddia'], '-l':['scale-free'], '-g':[0], '-lb':['1.21']})
    lsarg.append({'func':['-di'], 'files':['simdata/expsvcsimn_10k_10k_d2_a7_i10_avg1_8.json'], '-m':['bluepenta'], '-b':['100'], '-l':['exponential']})
    lsarg.append({'func':['-di'], 'files':['simdata/randsvcsimn_10k_10k_d2_a11_i10_avg1_8.json'], '-m':['trihexaorg'], '-b':['100'], '-l':['random'], '-logx':[1], '-logy':[1], '-xlim':[1, 500], '-ylim':[1e-6, 1], '-t':['Scale-free, exponential, and random network degree distribution'], '-xl':['In-degree $k_{in}$'], '-yl':['Probability distribution $P(k_{in})$'], '-axisfsize':['large'], '-ncol':[1], '-loc':[1]})

    for i in range(len(lsarg)):
        ds = []
        func = lsarg[i]['func'][0]

        step = p.STEP
        argstep = getargval(lsarg[i], '-j')
        if argstep:
            step = int(argstep[0])

        f = open(lsarg[i]['files'][0])
        try:
            data = json.load(f)

            p.loaddata(ds, func, data, lsarg[i]['files'][0], step)
        finally:
            f.close()

        logx = False
        arglogx = getargval(lsarg[i], '-logx')
        if arglogx:
            logx = int(arglogx[0]) > 0

        logy = False
        arglogy = getargval(lsarg[i], '-logy')
        if arglogy:
            logy = int(arglogy[0]) > 0

        lb = p.LOGBINBASE
        arglb = getargval(lsarg[i], '-lb')
        if arglb:
            lb = float(arglb[0])

        xlim = getargval(lsarg[i], '-xlim')
        ylim = getargval(lsarg[i], '-ylim')

        plotfile = getargval(lsarg[i], '-v', [None])[0]

        if func in [p.FUNC_LOGINDEG, p.FUNC_HISTINDEG]:
            xlabel = 'In-degree'
        elif func in [p.FUNC_LOGOUTDEG, p.FUNC_HISTOUTDEG]:
            xlabel = 'Out-degree'

        axisfsize = getargval(lsarg[i], '-axisfsize', ['medium'])[0]
        try:
            axisfsize = int(axisfsize)
        except:
            pass

        ncol = int(getargval(lsarg[i], '-ncol', [1])[0])
        numpoints = int(getargval(lsarg[i], '-numpoints', [1])[0])

        if func in [p.FUNC_LOGINDEG, p.FUNC_LOGOUTDEG]:
            # loglog degree distribution
            p.drawloglogdist(ds
                , xlabel=getargval(lsarg[i], '-xl', [''])[0]
                , ylabel=getargval(lsarg[i], '-yl', [''])[0]
                , title=getargval(lsarg[i], '-t', [''])[0]
                , labels=getargval(lsarg[i], '-l')
                , markset=getargval(lsarg[i], '-m', ['var'])[0]
                , xlim=xlim
                , ylim=ylim
                , axisfsize=axisfsize
                , logbinbase=lb
                , showexp=int(getargval(lsarg[i], '-g', [1])[0])
                , legloc=int(getargval(lsarg[i], '-loc', [1])[0])
                , ax=p.plt.gca()
                , ncol=ncol
                , numpoints=numpoints)

        elif func in [p.FUNC_DISTINDEG, p.FUNC_DISTOUTDEG]:
            # degree distribution plot

            if p.FUNC_DISTINDEG:
                title = getargval(lsarg[i], '-t', ['Degree distribution of exponential network'])[0]
                xylabels = {'x':getargval(lsarg[i], '-xl', ['k (degree)'])[0], 'y':getargval(lsarg[i], '-yl', ['P(k)'])[0]}
            else:
                title = getargval(lsarg[i], '-t', ['Outdegree distribution'])[0]
                xylabels = {'x':getargval(lsarg[i], '-xl', ['Outdegree'])[0], 'y':getargval(lsarg[i], '-yl', ['Number of nodes'])[0]}

            p.plotdegdist(ds
                , getargval(lsarg[i], '-l')
                , getargval(lsarg[i], '-m', ['var'])[0]
                , title=title
                , xylabels=xylabels
                , nbins=int(getargval(lsarg[i], '-b', ['50'])[0])
                , logx=logx, logy=logy
                , xlim=xlim
                , ylim=ylim
                , axisfsize=axisfsize
                , legloc=int(getargval(lsarg[i], '-loc', [1])[0])
                , ax=p.plt.gca()
                , ncol=ncol
                , numpoints=numpoints)

    p.processplot(p.plt, getargval(lsarg[i], '-s', [None])[0])
예제 #3
0
def main(argv):
    lsarg = []
    lsarg.append({'func':['-di'], 'files':['simdata/lg_comp.json'], '-m':['star'], '-t':['In-degree distribution of the Language Grid and ProgrammableWeb service networks'], '-xl':['In-degree $k_{in}$'], '-yl':['Probability distribution $P(k_{in})$\nThe Language Grid'], '-l':['The Language Grid'], '-loc':[2], '-axisfsize':['large'], '-logx':[1], '-logy':[1]})
    lsarg.append({'func':['-li'], 'files':['simdata/pwsvcsim_1.json'], '-m':['diamond'], '-yl':['ProgrammableWeb'], '-l':['ProgrammableWeb'], '-axisfsize':['large'], '-loc':[4], '-lb':[1.21], '-xlim':[-1,10000], '-logx':[1], '-logy':[1]})

    ax = p.plt.axes([0.13, 0.12, 0.6, 0.78])
    ax2 = p.plt.twinx(ax)

    for i in range(len(lsarg)):
        ds = []
        func = lsarg[i]['func'][0]

        step = p.STEP
        argstep = getargval(lsarg[i], '-j')
        if argstep:
            step = int(argstep[0])

        for finjson in lsarg[i]['files']:
            f = open(finjson)
            try:
                data = json.load(f)

                p.loaddata(ds, func, data, finjson, step)
            finally:
                f.close()

        logx = False
        arglogx = getargval(lsarg[i], '-logx')
        if arglogx:
            logx = int(arglogx[0]) > 0

        logy = False
        arglogy = getargval(lsarg[i], '-logy')
        if arglogy:
            logy = int(arglogy[0]) > 0

        lb = p.LOGBINBASE
        arglb = getargval(lsarg[i], '-lb')
        if arglb:
            lb = float(arglb[0])

        xlim = getargval(lsarg[i], '-xlim')
        ylim = getargval(lsarg[i], '-ylim')

        plotfile = getargval(lsarg[i], '-v', [None])[0]

        axisfsize = getargval(lsarg[i], '-axisfsize', ['medium'])[0]
        try:
            axisfsize = int(axisfsize)
        except:
            pass

        if i == 0:
            #func == p.FUNC_DISTINDEG:
            p.plotdegdist(ds
                , getargval(lsarg[i], '-l')
                , getargval(lsarg[i], '-m', ['var'])[0]
                , title=getargval(lsarg[i], '-t', [''])[0]
                , xylabels={'x': getargval(lsarg[i], '-xl', [''])[0], 'y': getargval(lsarg[i], '-yl', [''])[0]}
                , nbins=int(getargval(lsarg[i], '-b', ['50'])[0])
                , logx=logx, logy=logy
                , xlim=xlim
                , ylim=ylim
                , legloc=int(getargval(lsarg[i], '-loc', [2])[0])
                , axisfsize=axisfsize
                , ax=ax)
                #, ax=p.plt.twinx(p.plt.gca()))
                #, ax=p.plt.gca())

            ax.set_ylabel(ax.get_ylabel(), color='#460046')
            for tl in ax.get_yticklabels():
                tl.set_color('#460046')

        elif i == 1:
            #func == p.FUNC_LOGINDEG:

            p.drawloglogdist(ds
                , xlabel=getargval(lsarg[i], '-xl', [''])[0]
                , ylabel=getargval(lsarg[i], '-yl', [''])[0]
                , title=getargval(lsarg[i], '-t', [''])[0]
                , labels=getargval(lsarg[i], '-l')
                , markset=getargval(lsarg[i], '-m', ['var'])[0]
                , xlim=xlim
                , ylim=ylim
                , axisfsize=axisfsize
                , legloc=int(getargval(lsarg[i], '-loc', [2])[0])
                , logbinbase=lb
                , showexp=int(getargval(lsarg[i], '-g', [1])[0])
                , ax=ax2)
                #, ax=p.plt.twinx(ax))
                #, ax=p.plt.twinx(p.plt.gca()))

            ax2.set_ylabel(ax2.get_ylabel(), color='#003200')
            for tl in ax2.get_yticklabels():
                tl.set_color('#003200')

    p.processplot(p.plt, getargval(lsarg[i], '-s', [None])[0])
예제 #4
0
파일: plotdepall.py 프로젝트: kemas/ns3
def main(argv):
    oax = p.plt.gca()
    oax2 = p.plt.twinx(oax)

    lsarg = []
    lsarg.append(
        {
            "func": ["-fc"],
            "files": [
                "simdata/svcsimn_10k_10k_d2_a1_i10_avg1_8.json",
                "simdata/expsvcsimn_10k_10k_d2_a1_i10_avg1_8.json",
                "simdata/randsvcsimn_10k_10k_d2_a1_i10_avg1_8.json",
                "simdata/svcsimn_10k_10k_d3_a1_i10_avg1_8.json",
                "simdata/expsvcsimn_10k_10k_d3_a1_i10_avg1_8.json",
                "simdata/randsvcsimn_10k_10k_d3_a1_i10_avg1_8.json",
                "simdata/svcsimn_10k_10k_d4_a1_i10_avg1_8.json",
                "simdata/expsvcsimn_10k_10k_d4_a1_i10_avg1_8.json",
                "simdata/randsvcsimn_10k_10k_d4_a1_i10_avg1_8.json",
            ],
            "-m": ["tricol"],
            "-j": [500],
            "-l": [
                "sf, $\langle{dep}\\rangle = 1$",
                "exp, $\langle{dep}\\rangle = 1$",
                "rand, $\langle{dep}\\rangle = 1$",
                "sf, $\langle{dep}\\rangle \\approx 1.5$",
                "exp, $\langle{dep}\\rangle \\approx 1.5$",
                "rand, $\langle{dep}\\rangle \\approx 1.5$",
                "sf, $\langle{dep}\\rangle \\approx 2$",
                "exp, $\langle{dep}\\rangle \\approx 2$",
                "rand, $\langle{dep}\\rangle \\approx 2$",
            ],
            "-axisfsize": ["large"],
            "-ncol": [3],
            "-ax": [oax],
            "-ylim": [-0.02, 0.36],
            "-t": ["Cascading failure with different $\langle{dep}\\rangle$ in service networks"],
            "-xl": ["Random failed services $n_r$ (in fraction)"],
            "-yl": ["Cascade failed services $n_c$ (in fraction)"],
        }
    )
    lsarg.append(
        {
            "func": ["-fc"],
            "files": ["simdata/pwsvcsim_avg1_16.json"],
            "-m": ["diamond"],
            "-j": [500],
            "-l": ["ProgrammableWeb"],
            "-axisfsize": ["large"],
            "-ax": [oax2],
        }
    )
    lsarg.append(
        {
            "func": ["-fc"],
            "files": ["simdata/lgsvcsim_avg1_16.json"],
            "-m": ["star"],
            "-j": [10],
            "-l": ["The Language Grid"],
            "-axisfsize": ["large"],
            "-ncol": [3],
            "-ax": [oax2],
            "-ylim": [-0.02, 0.36],
            "-loc": [4],
        }
    )

    for i in range(len(lsarg)):
        ds = []
        func = lsarg[i]["func"][0]

        ax = getargval(lsarg[i], "-ax")[0]

        step = p.STEP
        argstep = getargval(lsarg[i], "-j")
        if argstep:
            step = int(argstep[0])

        for finjson in lsarg[i]["files"]:
            f = open(finjson)
            try:
                data = json.load(f)

                p.loaddata(ds, func, data, finjson, step)
            finally:
                f.close()

        logx = False
        arglogx = getargval(lsarg[i], "-logx")
        if arglogx:
            logx = int(arglogx[0]) > 0

        logy = False
        arglogy = getargval(lsarg[i], "-logy")
        if arglogy:
            logy = int(arglogy[0]) > 0

        lb = p.LOGBINBASE
        arglb = getargval(lsarg[i], "-lb")
        if arglb:
            lb = float(arglb[0])

        xlim = getargval(lsarg[i], "-xlim")
        ylim = getargval(lsarg[i], "-ylim")

        plotfile = getargval(lsarg[i], "-v", [None])[0]

        axisfsize = getargval(lsarg[i], "-axisfsize", ["medium"])[0]
        try:
            axisfsize = int(axisfsize)
        except:
            pass

        ncol = int(getargval(lsarg[i], "-ncol", [1])[0])

        legmode = getargval(lsarg[i], "-lm", ["normal"])[0]
        bbox_to_anchor = getargval(lsarg[i], "-lbb", None)

        if func in [p.FUNC_FAIL, p.FUNC_FAILCASC]:
            p.plotfailnodes(
                ds,
                getargval(lsarg[i], "-l"),
                getargval(lsarg[i], "-m", ["var"])[0],
                isbase=func == p.FUNC_FAIL,
                xylabels={"x": getargval(lsarg[i], "-xl", [""])[0], "y": getargval(lsarg[i], "-yl", [""])[0]},
                title=getargval(lsarg[i], "-t", [""])[0],
                legloc=int(getargval(lsarg[i], "-loc", [2])[0]),
                xlim=xlim,
                ylim=ylim,
                axisfsize=axisfsize,
                ax=ax,
                ncol=ncol,
                legmode=legmode,
                bbox_to_anchor=bbox_to_anchor,
            )

    oax2.get_yaxis().set_visible(False)
    #    # clean some ticks of the left y-axis
    #    yts = oax.get_yaxis().get_major_ticks()
    #    yts[-2].label.set_visible(False)
    #    yts[-3].label.set_visible(False)

    p.processplot(p.plt, getargval(lsarg[i], "-s", [None])[0])
예제 #5
0
파일: plotpwlg_ori.py 프로젝트: kemas/ns3
def main(argv):
    lsarg = []
    lsarg.append({'func':['-fc'], 'files':['simdata/pwsvcsim_avg1_16.json'], '-m':['diamond'], '-j':[500], '-l':['ProgrammableWeb'], '-axisfsize':['large']})
    lsarg.append({'func':['-fc'], 'files':['simdata/lgsvcsim_avg1_16.json'], '-m':['star'], '-j':[10], '-t':['Cascading failure on real networks'], '-xl':['Random failed services $n_r$ (in fraction)'], '-yl':['Cascade failed services $n_c$ (in fraction)'], '-l':['The Language Grid'], '-loc':[2], '-axisfsize':['large']})

    for i in range(len(lsarg)):
        ds = []
        func = lsarg[i]['func'][0]

        step = p.STEP
        argstep = getargval(lsarg[i], '-j')
        if argstep:
            step = int(argstep[0])

        for finjson in lsarg[i]['files']:
            f = open(finjson)
            try:
                data = json.load(f)

                p.loaddata(ds, func, data, finjson, step)
            finally:
                f.close()

        logx = False
        arglogx = getargval(lsarg[i], '-logx')
        if arglogx:
            logx = int(arglogx[0]) > 0

        logy = False
        arglogy = getargval(lsarg[i], '-logy')
        if arglogy:
            logy = int(arglogy[0]) > 0

        lb = p.LOGBINBASE
        arglb = getargval(lsarg[i], '-lb')
        if arglb:
            lb = float(arglb[0])

        xlim = getargval(lsarg[i], '-xlim')
        ylim = getargval(lsarg[i], '-ylim')

        plotfile = getargval(lsarg[i], '-v', [None])[0]

        axisfsize = getargval(lsarg[i], '-axisfsize', ['medium'])[0]
        try:
            axisfsize = int(axisfsize)
        except:
            pass

        ax = p.plt.gca()

        if func in [p.FUNC_FAIL, p.FUNC_FAILCASC]:
            p.plotfailnodes(ds
                , getargval(lsarg[i], '-l')
                , getargval(lsarg[i], '-m', ['var'])[0]
                , isbase=func==p.FUNC_FAIL
                , xylabels={'x': getargval(lsarg[i], '-xl', [''])[0], 'y': getargval(lsarg[i], '-yl', [''])[0]}
                , title=getargval(lsarg[i], '-t', [''])[0]
                , legloc=int(getargval(lsarg[i], '-loc', [2])[0])
                , xlim=xlim
                , ylim=ylim
                , axisfsize=axisfsize
                , ax=ax)

            # process legend independently
            #legend = p.plt.legend([ax.get_lines()[0]], loc=int(getargval(lsarg[i], '-loc', [2])[0]))
            # add the legend to te axes
            #ax.add_artist(legend)

    p.processplot(p.plt, getargval(lsarg[i], '-s', [None])[0])
예제 #6
0
파일: plotaltall.py 프로젝트: kemas/ns3
def main(argv):
    oax = p.plt.gca()
    oax2 = p.plt.twinx(oax)

    lsarg = []
    lsarg.append({'func':['-fc'], 'files':['simdata/svcsimn_10k_10k_d2_a2_i10_avg1_8.json', 'simdata/expsvcsimn_10k_10k_d2_a2_i10_avg1_8.json', 'simdata/randsvcsimn_10k_10k_d2_a2_i10_avg1_8.json', 'simdata/svcsimn_10k_10k_d2_a3_i10_avg1_8.json', 'simdata/expsvcsimn_10k_10k_d2_a3_i10_avg1_8.json', 'simdata/randsvcsimn_10k_10k_d2_a3_i10_avg1_8.json', 'simdata/svcsimn_10k_10k_d2_a4_i10_avg1_8.json', 'simdata/expsvcsimn_10k_10k_d2_a4_i10_avg1_8.json', 'simdata/randsvcsimn_10k_10k_d2_a4_i10_avg1_8.json'], '-m':['tricol'], '-j':[500], '-l':['sf, $\langle{alt}\\rangle = 0$', 'exp, $\langle{alt}\\rangle = 0$', 'rand, $\langle{alt}\\rangle = 0$', 'sf, $\langle{alt}\\rangle \\approx 0.5$', 'exp, $\langle{alt}\\rangle \\approx 0.5$', 'rand, $\langle{alt}\\rangle \\approx 0.5$', 'sf, $\langle{alt}\\rangle \\approx 1$', 'exp, $\langle{alt}\\rangle \\approx 1$', 'rand, $\langle{alt}\\rangle \\approx 1$'], '-axisfsize':['large'], '-ncol':[3], '-ax':[oax], '-ylim':[-0.02, 0.25], '-t':['Cascading failure with different $\langle{alt}\\rangle$ in service networks'], '-xl':['Random failed services $n_r$ (in fraction)'], '-yl':['Cascade failed services $n_c$ (in fraction)']})
    lsarg.append({'func':['-fc'], 'files':['simdata/pwsvcsim_avg1_16.json'], '-m':['diamond'], '-j':[500], '-l':['ProgrammableWeb'], '-axisfsize':['large'], '-ax':[oax2]})
    lsarg.append({'func':['-fc'], 'files':['simdata/lgsvcsim_avg1_16.json'], '-m':['star'], '-j':[10], '-l':['The Language Grid'], '-axisfsize':['large'], '-ncol':[3], '-ax':[oax2], '-ylim':[-0.02, 0.25], '-loc':[4]})

    for i in range(len(lsarg)):
        ds = []
        func = lsarg[i]['func'][0]

        ax = getargval(lsarg[i], '-ax')[0]

        step = p.STEP
        argstep = getargval(lsarg[i], '-j')
        if argstep:
            step = int(argstep[0])

        for finjson in lsarg[i]['files']:
            f = open(finjson)
            try:
                data = json.load(f)

                p.loaddata(ds, func, data, finjson, step)
            finally:
                f.close()

        logx = False
        arglogx = getargval(lsarg[i], '-logx')
        if arglogx:
            logx = int(arglogx[0]) > 0

        logy = False
        arglogy = getargval(lsarg[i], '-logy')
        if arglogy:
            logy = int(arglogy[0]) > 0

        lb = p.LOGBINBASE
        arglb = getargval(lsarg[i], '-lb')
        if arglb:
            lb = float(arglb[0])

        xlim = getargval(lsarg[i], '-xlim')
        ylim = getargval(lsarg[i], '-ylim')

        plotfile = getargval(lsarg[i], '-v', [None])[0]

        axisfsize = getargval(lsarg[i], '-axisfsize', ['medium'])[0]
        try:
            axisfsize = int(axisfsize)
        except:
            pass

        ncol = int(getargval(lsarg[i], '-ncol', [1])[0])

        legmode = getargval(lsarg[i], '-lm', ['normal'])[0]
        bbox_to_anchor = getargval(lsarg[i], '-lbb', None)

        if func in [p.FUNC_FAIL, p.FUNC_FAILCASC]:
            p.plotfailnodes(ds
                , getargval(lsarg[i], '-l')
                , getargval(lsarg[i], '-m', ['var'])[0]
                , isbase=func==p.FUNC_FAIL
                , xylabels={'x': getargval(lsarg[i], '-xl', [''])[0], 'y': getargval(lsarg[i], '-yl', [''])[0]}
                , title=getargval(lsarg[i], '-t', [''])[0]
                , legloc=int(getargval(lsarg[i], '-loc', [2])[0])
                , xlim=xlim
                , ylim=ylim
                , axisfsize=axisfsize
                , ax=ax
                , ncol=ncol
                , legmode=legmode
                , bbox_to_anchor=bbox_to_anchor)

    oax2.get_yaxis().set_visible(False)
    #oax.get_yaxis().set_ticks()

    p.processplot(p.plt, getargval(lsarg[i], '-s', [None])[0])
예제 #7
0
파일: plotsfexprand.py 프로젝트: kemas/ns3
def main(argv):
    lsarg = []

    lsarg.append(
        {
            "func": ["-li"],
            "files": ["simdata/svcsimn_10k_10k_d2_a7_i10_avg1_8.json"],
            "-m": ["reddia"],
            "-l": ["scale-free"],
            "-g": [0],
            "-lb": ["1.21"],
            "-gl": [0],
        }
    )
    lsarg.append(
        {
            "func": ["-di"],
            "files": ["simdata/expsvcsimn_10k_10k_d2_a7_i10_avg1_8.json"],
            "-m": ["bluepenta"],
            "-b": ["100"],
            "-l": ["exponential"],
        }
    )
    lsarg.append(
        {
            "func": ["-di"],
            "files": ["simdata/randsvcsimn_10k_10k_d2_a11_i10_avg1_8.json"],
            "-m": ["trihexaorg"],
            "-b": ["100"],
            "-l": ["random"],
            "-logx": [1],
            "-logy": [1],
            "-xlim": [1, 500],
            "-ylim": [1e-6, 1],
            "-t": ["Scale-free, exponential, and random network degree distribution"],
            "-xl": ["In-degree $k_{in}$"],
            "-yl": ["Probability distribution $P(k_{in})$"],
            "-axisfsize": ["large"],
            "-ncol": [1],
            "-loc": [1],
        }
    )

    for i in range(len(lsarg)):
        ds = []
        func = lsarg[i]["func"][0]

        step = p.STEP
        argstep = getargval(lsarg[i], "-j")
        if argstep:
            step = int(argstep[0])

        f = open(lsarg[i]["files"][0])
        try:
            data = json.load(f)

            p.loaddata(ds, func, data, lsarg[i]["files"][0], step)
        finally:
            f.close()

        logx = False
        arglogx = getargval(lsarg[i], "-logx")
        if arglogx:
            logx = int(arglogx[0]) > 0

        logy = False
        arglogy = getargval(lsarg[i], "-logy")
        if arglogy:
            logy = int(arglogy[0]) > 0

        lb = p.LOGBINBASE
        arglb = getargval(lsarg[i], "-lb")
        if arglb:
            lb = float(arglb[0])

        xlim = getargval(lsarg[i], "-xlim")
        ylim = getargval(lsarg[i], "-ylim")

        plotfile = getargval(lsarg[i], "-v", [None])[0]

        if func in [p.FUNC_LOGINDEG, p.FUNC_HISTINDEG]:
            xlabel = "In-degree"
        elif func in [p.FUNC_LOGOUTDEG, p.FUNC_HISTOUTDEG]:
            xlabel = "Out-degree"

        axisfsize = getargval(lsarg[i], "-axisfsize", ["medium"])[0]
        try:
            axisfsize = int(axisfsize)
        except:
            pass

        ncol = int(getargval(lsarg[i], "-ncol", [1])[0])
        numpoints = int(getargval(lsarg[i], "-numpoints", [1])[0])

        if func in [p.FUNC_LOGINDEG, p.FUNC_LOGOUTDEG]:
            # loglog degree distribution
            p.drawloglogdist(
                ds,
                xlabel=getargval(lsarg[i], "-xl", [""])[0],
                ylabel=getargval(lsarg[i], "-yl", [""])[0],
                title=getargval(lsarg[i], "-t", [""])[0],
                labels=getargval(lsarg[i], "-l"),
                markset=getargval(lsarg[i], "-m", ["var"])[0],
                xlim=xlim,
                ylim=ylim,
                axisfsize=axisfsize,
                logbinbase=lb,
                showexp=int(getargval(lsarg[i], "-g", [1])[0]),
                legloc=int(getargval(lsarg[i], "-loc", [1])[0]),
                ax=p.plt.gca(),
                ncol=ncol,
                numpoints=numpoints,
                isexpline=int(getargval(lsarg[i], "-gl", [1])[0]),
            )

        elif func in [p.FUNC_DISTINDEG, p.FUNC_DISTOUTDEG]:
            # degree distribution plot

            if p.FUNC_DISTINDEG:
                title = getargval(lsarg[i], "-t", ["Degree distribution of exponential network"])[0]
                xylabels = {
                    "x": getargval(lsarg[i], "-xl", ["k (degree)"])[0],
                    "y": getargval(lsarg[i], "-yl", ["P(k)"])[0],
                }
            else:
                title = getargval(lsarg[i], "-t", ["Outdegree distribution"])[0]
                xylabels = {
                    "x": getargval(lsarg[i], "-xl", ["Outdegree"])[0],
                    "y": getargval(lsarg[i], "-yl", ["Number of nodes"])[0],
                }

            p.plotdegdist(
                ds,
                getargval(lsarg[i], "-l"),
                getargval(lsarg[i], "-m", ["var"])[0],
                title=title,
                xylabels=xylabels,
                nbins=int(getargval(lsarg[i], "-b", ["50"])[0]),
                logx=logx,
                logy=logy,
                xlim=xlim,
                ylim=ylim,
                axisfsize=axisfsize,
                legloc=int(getargval(lsarg[i], "-loc", [1])[0]),
                ax=p.plt.gca(),
                ncol=ncol,
                numpoints=numpoints,
            )

    p.processplot(p.plt, getargval(lsarg[i], "-s", [None])[0])
예제 #8
0
파일: plotpwlg_alt.py 프로젝트: kemas/ns3
def main(argv):
    lsarg = []
    lsarg.append({'func':['-fc'], 'files':['simdata/pwsvcsim_avg1_16.json', 'simdata/pwsvcsim_a2_avg1_16.json', 'simdata/pwsvcsim_a3_avg1_16.json'], '-m':['green'], '-j':[500]})
    lsarg.append({'func':['-fc'], 'files':['simdata/lgsvcsim_avg1_16.json', 'simdata/lgsvcsim_a2_avg1_16.json', 'simdata/lgsvcsim_a3_avg1_16.json'], '-m':['cyan'], '-j':[10], '-t':['Cascading failure with different $\langle{alt}\\rangle$ on real networks'], '-xl':['Random failed services $n_r$ (in fraction)'], '-yl':['Cascade failed services $n_c$ (in fraction)']})

    fig = p.plt.figure()

    for i in range(len(lsarg)):
        ds = []
        func = lsarg[i]['func'][0]

        step = p.STEP
        argstep = getargval(lsarg[i], '-j')
        if argstep:
            step = int(argstep[0])

        for finjson in lsarg[i]['files']:
            f = open(finjson)
            try:
                data = json.load(f)

                p.loaddata(ds, func, data, finjson, step)
            finally:
                f.close()

        logx = False
        arglogx = getargval(lsarg[i], '-logx')
        if arglogx:
            logx = int(arglogx[0]) > 0

        logy = False
        arglogy = getargval(lsarg[i], '-logy')
        if arglogy:
            logy = int(arglogy[0]) > 0

        lb = p.LOGBINBASE
        arglb = getargval(lsarg[i], '-lb')
        if arglb:
            lb = float(arglb[0])

        xlim = getargval(lsarg[i], '-xlim')
        ylim = getargval(lsarg[i], '-ylim')

        plotfile = getargval(lsarg[i], '-v', [None])[0]

        if func in [p.FUNC_LOGINDEG, p.FUNC_HISTINDEG]:
            xlabel = 'In-degree'
        elif func in [p.FUNC_LOGOUTDEG, p.FUNC_HISTOUTDEG]:
            xlabel = 'Out-degree'

        axisfsize = getargval(lsarg[i], '-axisfsize', ['medium'])[0]
        try:
            axisfsize = int(axisfsize)
        except:
            pass

        if func in [p.FUNC_FAIL, p.FUNC_FAILCASC]:
            p.plotfailnodes(ds
                , getargval(lsarg[i], '-l')
                , getargval(lsarg[i], '-m', ['var'])[0]
                , isbase=func==p.FUNC_FAIL
                , xylabels={'x': getargval(lsarg[i], '-xl', [''])[0], 'y': getargval(lsarg[i], '-yl', [''])[0]}
                , title=getargval(lsarg[i], '-t', [''])[0]
                , legloc=int(getargval(lsarg[i], '-loc', [2])[0])
                , xlim=xlim
                , ylim=ylim
                , axisfsize=axisfsize
                , fig=fig)

    p.processplot(p.plt, getargval(lsarg[i], '-s', [None])[0])