Пример #1
0
def plotter(df, fname, ylabel, args):
    plt = df.dropna().plot(**args)
    fontdict = {
        'fontsize': args['fontsize'],
    } if 'fontsize' in args else None
    
    plt.set_xlabel('Traffic segments', fontdict=fontdict)
    plt.set_ylabel(ylabel, fontdict=fontdict)
    # plt.set_ylim(padding(df))
    plt.grid(axis='y')

    (x, y) = args['figsize']
    if x * y < 50:
        plt.tick_params(
            axis='x',          # changes apply to the x-axis
            which='both',      # both major and minor ticks are affected
            bottom='on',       # ticks along the bottom edge are off
            top='off',         # ticks along the top edge are off
            labelbottom='off') # labels along the bottom edge are off
    
    utils.mkplot_(plt, fname)
Пример #2
0
def heatplot(fig, directory, fname, labels, extension='png'):
    fig.set(**labels)
    f = Path(args.figures, fname).with_suffix('.' + extension)
    utils.mkplot_(fig, str(f))
Пример #3
0
pivot = 'depth'
groups = list(p.slices.keys()) + [pivot, 'node']
metrics = collections.OrderedDict({
    'f1_score': 'F$_{1}$',
    'matthews_corrcoef': 'MCC',
})

path = pathlib.PurePath('log', p.directory)

dat = pathlib.Path(path, 'dat')
raw = pd.DataFrame.from_csv(str(dat), sep=';', index_col=None)

grouped = raw.groupby(groups)[list(metrics.keys())]

df = grouped.agg([np.mean])
for i in p.slices.values():
    df = df.loc[i]

df = df.unstack(level=pivot)
df.rename(columns=lambda x: metrics[x] if x in metrics else x, inplace=True)

operations = [df.mean, df.sem]
(means, errors) = [f().unstack(level=0).loc['mean'] for f in operations]
fig = means.plot(yerr=errors, kind='bar')

fname = 'neighbor-' + '_'.join(map(str, p.slices.values()))
dat = pathlib.Path(path, 'fig', fname).with_suffix('.' + 'png')
print(dat)

utils.mkplot_(fig, str(dat))
Пример #4
0
path = pathlib.PurePath('log', p.directory)
dat = pathlib.Path(path, 'dat')

raw = pd.DataFrame.from_csv(str(dat), sep=';', index_col=None)
grouped = raw.groupby(groups)[list(metrics.keys())]

df = grouped.agg([ np.mean ])
for i in p.slices.values():
    df = df.loc[i]
df = df.unstack(level=pivot)

stats = []
for i in (df.mean, df.sem):
    d = i()
    level = d.index.names.index(pivot[0])
    d = d.unstack(level=level)

    # level = len(metrics.keys()) + 1
    d.index = d.index.droplevel([0, 1])
    stats.append(d)
(means, errors) = stats

yticks = np.linspace(0, 1, 11)
fig = means.plot(kind='bar', yerr=errors, ylim=(0,1), yticks=yticks)

fname = 'neighbor-' + '_'.join(map(str, p.slices.values()))
dat = pathlib.Path(path, 'fig', fname).with_suffix('.' + 'png')
print(dat)

utils.mkplot_(fig, str(dat))
Пример #5
0
# import matplotlib
# matplotlib.style.use('ggplot')
import matplotlib.pyplot as plt
plt.style.use('ggplot')

from lib import db
from lib import utils

with db.DatabaseConnection() as con:
    sql = [
        'SELECT frequency / {0} AS freq',
        'FROM quality',
        'ORDER BY frequency ASC',
    ]
    sql = db.process(sql, [ constant.minute ])
    df = pd.read_sql_query(sql, con=con)

df['dist'] = df.apply(lambda x: (x.index + 1) / len(df))

args = {
    'xlim': (1, 5),
    'ylim': (0, 1),
    'yticks': np.linspace(0, 1, 11),
    'legend': False
    }
plot = df.plot(x='freq', y='dist', **args)
plot.set_xlabel('Reporting frequency (min)')
plot.set_ylabel('Fraction of segments')

utils.mkplot_(plot, 'reporting.png')