Exemplo n.º 1
0
def hist(dataset, **kwargs):
    defaults = {
        'grid': False,
        'xlabel': '',
        'ylabel': '',
        'title': '',
        'output': None,
    }
    plot_params = {
        'bins': 20,
        'normed': 1,
        'facecolor': 'green',
        'alpha': 0.75,
    }
    plot_params.update(kwargs)
    [plot_params.pop(k) for k in defaults if k in plot_params]
    defaults.update(kwargs)

    values = list(Dataset.get_num_column_or_list(dataset))

    n, bins, patches = plt.hist(values, **plot_params)
    plt.xlabel(defaults['xlabel'])
    plt.ylabel(defaults['ylabel'])
    plt.title(defaults['title'])
    plt.grid(defaults['grid'])

    filename = defaults['output'] or get_tmp_file_name('.png')
    plt.savefig(filename)

    return filename
Exemplo n.º 2
0
Arquivo: graph.py Projeto: amadev/doan
def hist(dataset, **kwargs):
    defaults = {
        'grid': False,
        'xlabel': '',
        'ylabel': '',
        'title': '',
        'output': None,
    }
    graph_params = {
        'bins': 20,
        'normed': 1,
        'facecolor': 'green',
        'alpha': 0.75,
    }
    graph_params.update(kwargs)
    defaults.update(kwargs)
    [graph_params.pop(k) for k in defaults if k in graph_params]

    values = list(Dataset.get_num_column_or_list(dataset))

    n, bins, patches = plt.hist(values, **graph_params)
    plt.xlabel(defaults['xlabel'])
    plt.ylabel(defaults['ylabel'])
    plt.title(defaults['title'])
    plt.grid(defaults['grid'])

    filename = defaults['output'] or get_tmp_file_name('.png')
    plt.savefig(filename)

    return filename
Exemplo n.º 3
0
def plot_date(datasets, **kwargs):
    """Plot points with dates.

    datasets can be Dataset object or list of Dataset.
    """

    defaults = {
        'grid': True,
        'xlabel': '',
        'ylabel': '',
        'title': '',
        'output': None,
    }
    graph_params = {
        'color': 'b',
        'ls': '',
        'alpha': 0.75,
    }
    graph_params.update(kwargs)
    [plot_params.pop(k) for k in defaults if k in plot_params]
    defaults.update(kwargs)

    if isinstance(datasets, Dataset):
        datasets = [datasets]

    colors = ['b', 'g', 'r', 'c', 'm', 'y', 'k']
    color = plot_params.pop('color')
    try:
        del colors[colors.index(color)]
        colors.insert(0, color)
    except IndexError:
        pass
    colors = cycle(colors)

    fig, ax = plt.subplots()
    #ax.fmt_xdata = DateFormatter("%H:%M")
    fig.autofmt_xdate()
    ax.autoscale_view()

    for dataset in datasets:
        if isinstance(dataset, Dataset):
            dates = list(dataset.get_column_by_type(dataset.DATE))
            values = list(dataset.get_column_by_type(dataset.NUM))
            label = dataset.name
        else:
            dates, values = dataset
            label = ''
        dates = date2num(dates)
        color = next(colors)
        plt.plot_date(dates, values, color=color, label=label, **plot_params)

    plt.xlabel(defaults['xlabel'])
    plt.ylabel(defaults['ylabel'])
    plt.title(defaults['title'])
    plt.grid(defaults['grid'])

    plt.legend(loc='best', prop={'size': 10})
    filename = defaults['output'] or get_tmp_file_name('.png')
    plt.savefig(filename)
    return filename
Exemplo n.º 4
0
Arquivo: graph.py Projeto: amadev/doan
def plot_date(datasets, **kwargs):
    """Plot points with dates.

    datasets can be Dataset object or list of Dataset.
    """

    defaults = {
        'grid': True,
        'xlabel': '',
        'ylabel': '',
        'title': '',
        'output': None,
    }
    graph_params = {
        'color': 'b',
        'ls': '',
        'alpha': 0.75,
    }
    graph_params.update(kwargs)
    defaults.update(kwargs)
    [graph_params.pop(k) for k in defaults if k in graph_params]

    if isinstance(datasets, Dataset):
        datasets = [datasets]

    colors = ['b', 'g', 'r', 'c', 'm', 'y', 'k']
    color = graph_params.pop('color')
    try:
        del colors[colors.index(color)]
        colors.insert(0, color)
    except IndexError:
        pass
    colors = cycle(colors)

    fig, ax = plt.subplots()
    #ax.fmt_xdata = DateFormatter("%H:%M")
    fig.autofmt_xdate()
    ax.autoscale_view()

    for dataset in datasets:
        if isinstance(dataset, Dataset):
            dates = list(dataset.get_column_by_type(dataset.DATE))
            values = list(dataset.get_column_by_type(dataset.NUM))
            label = dataset.name
        else:
            dates, values = dataset
            label = ''
        dates = date2num(dates)
        color = next(colors)
        plt.plot_date(dates, values, color=color, label=label, **graph_params)

    plt.xlabel(defaults['xlabel'])
    plt.ylabel(defaults['ylabel'])
    plt.title(defaults['title'])
    plt.grid(defaults['grid'])

    plt.legend(loc='best', prop={'size':10})
    filename = defaults['output'] or get_tmp_file_name('.png')
    plt.savefig(filename)
    return filename
Exemplo n.º 5
0
 def wrapped(command):
     fn = get_tmp_file_name()
     check_call('ssh {} "{} > {}"\n'.format(
         host, command.replace(r'"', r'\"').replace('$', r'\$'), fn),
                shell=True)
     check_call('scp {0}:{1} {1}'.format(host, fn),
                shell=True)
     return fn
Exemplo n.º 6
0
 def wrapped(command):
     fn = get_tmp_file_name()
     check_call('ssh {} "{} > {}"\n'.format(
         host,
         command.replace(r'"', r'\"').replace('$', r'\$'), fn),
                shell=True)
     check_call('scp {0}:{1} {1}'.format(host, fn), shell=True)
     return fn
Exemplo n.º 7
0
def cmd(command):
    fn = get_tmp_file_name()
    check_call(command + ' > {}'.format(fn), shell=True)
    return fn
Exemplo n.º 8
0
def cmd(command):
    fn = get_tmp_file_name()
    check_call(command + ' > {}'.format(fn), shell=True)
    return fn