Python plotly.plotly 模块,sign_in() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用plotly.plotly.sign_in()

项目:pymoku    作者:liquidinstruments    | 项目源码 | 文件源码
def plot_frame(dataframe, uname=None, api_key=None, mode='lines', line={}):
    try:
        import plotly.plotly as ply
        import plotly.tools as ptls
        from plotly.graph_objs import Scatter, Layout, Data, Figure
    except ImportError:
        raise InvalidOperationException("Please install the Python plotly bindings")

    if uname and api_key:
        ply.sign_in(uname, api_key)

    c1 = dataframe.ch1
    c2 = dataframe.ch2
    x = list(range(len(c1)))

    t1 = Scatter(x=x, y=c1, mode=mode, line=line)
    t2 = Scatter(x=x, y=c2, mode=mode, line=line)

    layout = Layout(title="Moku:Lab Frame Grab")
    data = Data([t1, t2])

    fig = Figure(data=data, layout=layout)

    return ply.plot(fig)
项目:octogrid    作者:plotly    | 项目源码 | 文件源码
def login_as_bot():
    """
    Login as the bot account "octogrid", if user isn't authenticated on Plotly
    """

    plotly_credentials_file = join(
        join(expanduser('~'), PLOTLY_DIRECTORY), PLOTLY_CREDENTIALS_FILENAME)

    if isfile(plotly_credentials_file):
        with open(plotly_credentials_file, 'r') as f:
            credentials = loads(f.read())

        if (credentials['username'] == '' or credentials['api_key'] == ''):
            plotly.sign_in(BOT_USERNAME, BOT_API_KEY)
    else:
        plotly.sign_in(BOT_USERNAME, BOT_API_KEY)
项目:LoveIsInTheAir-Stats-Plotter    作者:sahilsareen    | 项目源码 | 文件源码
def __init__(self, labels, values, username, api_key, plot_name):
        self.logger = logging.getLogger(self.__class__.__name__)
        py.sign_in(username, api_key)
        fig = {
            'data': [{'labels': labels,
                      'values': values,
                      'type': 'pie'}],
            'layout': {'title': "Valentines week - %s #LoveIsInTheAir" % plot_name}
        }
        url = py.plot(fig, filename="Pie Chart %s" % plot_name)
        self.logger.info("Plotted Pie Chart: %s" % url)
项目:lddmm-ot    作者:jeanfeydy    | 项目源码 | 文件源码
def _plot_option_logic(plot_options_from_call_signature):
    """
    Given some plot_options as part of a plot call, decide on final options.
    Precedence:
        1 - Start with DEFAULT_PLOT_OPTIONS
        2 - Update each key with ~/.plotly/.config options (tls.get_config)
        3 - Update each key with session plot options (set by py.sign_in)
        4 - Update each key with plot, iplot call signature options

    """
    default_plot_options = copy.deepcopy(DEFAULT_PLOT_OPTIONS)
    file_options = tools.get_config_file()
    session_options = get_session_plot_options()
    plot_options_from_call_signature = copy.deepcopy(plot_options_from_call_signature)

    # Validate options and fill in defaults w world_readable and sharing
    for option_set in [plot_options_from_call_signature,
                       session_options, file_options]:
        utils.validate_world_readable_and_sharing_settings(option_set)
        utils.set_sharing_and_world_readable(option_set)

        # dynamic defaults
        if ('filename' in option_set and
                'fileopt' not in option_set):
            option_set['fileopt'] = 'overwrite'

    user_plot_options = {}
    user_plot_options.update(default_plot_options)
    user_plot_options.update(file_options)
    user_plot_options.update(session_options)
    user_plot_options.update(plot_options_from_call_signature)
    user_plot_options = {k: v for k, v in user_plot_options.items()
                         if k in default_plot_options}

    return user_plot_options
项目:epilepsy_diary    作者:bfortuner    | 项目源码 | 文件源码
def build_grouped_bar_chart(chart_data):
    print "Building Chart with data: " + str(chart_data)
    py.sign_in(config.PLOTLY_USERNAME, config.PLOTLY_PASSWORD)
    bars = []
    for name in chart_data['groups']:
        x_data_list = chart_data["x"]["data"][name]
        y_data_list = chart_data["y"]["data"][name]
        bar = go.Bar(
            x=x_data_list,
            y=y_data_list,
            name=name
        )
        bars.append(bar)

    chart_layout = dict(
        title=chart_data['title'],
        xaxis=dict(title=chart_data['x']['label'],
                   tickangle=-45, rangemode='tozero'),
        yaxis=dict(title=chart_data['y']['label'],
                   rangemode='tozero')
    )
    chart = go.Figure(data=bars, layout=chart_layout)
    filename = id_generator.generate_chart_image_filename()
    filepath = config.LOCAL_CHARTS_DIR_PATH + filename
    py.image.save_as(chart, filename=filepath)
    s3.upload_file(filename, filepath, config.S3_USER_CHARTS_BUCKET)
    download_url = s3.get_download_url(
        bucket=config.S3_USER_CHARTS_BUCKET,
        path=filename,
        expiry=603148)

    cleanup_file(filepath)

    return download_url
项目:tickerbot    作者:shaileshahuja    | 项目源码 | 文件源码
def plot_graph(traces, title):
    py.sign_in(settings.PLOTLY_USERNAME, settings.PLOTLY_PASSWORD)
    filename = str(uuid.uuid4()) + ".png"
    layout = go.Layout(title=title, width=800, height=640)
    fig = go.Figure(data=traces, layout=layout)
    # plot_file = offline.plot(fig, show_link=False, auto_open=False,
    #                          filename=settings.MEDIA_ROOT + filename,
    #                          include_plotlyjs=True)
    # ghost = Ghost()
    # page, resources = ghost.open(plot_file)
    plot_url = py.plot(fig, filename=filename, auto_open=False, file_opt='new')
    return plot_url + ".png"
    # return "http://8d30bf7d.ngrok.io/media/" + filename + ".html"
项目:evologger    作者:freeranger    | 项目源码 | 文件源码
def write(timestamp, temperatures):

    if invalidConfig:
        if plotly_debugEnabled:
            plotly_logger.debug('Invalid config, aborting write')
            return []

    debug_message = 'Writing to ' + plugin_name
    if not plotly_writeEnabled:
        debug_message += ' [SIMULATED]'
    plotly_logger.debug(debug_message)

    debug_text = '%s: ' % timestamp

    if plotly_writeEnabled:
        # Stream tokens from plotly
        tls.set_credentials_file(stream_ids=stream_ids_array)

    try:
        if plotly_writeEnabled:
            py.sign_in(plotly_username, plotly_api_key)

        for temperature in temperatures:
            debug_text += "%s (%s A" % (temperature.zone, temperature.actual)
            if temperature.target is not None:
                debug_text += ", %s T" % temperature.target
            debug_text += ') '

            if plotly_writeEnabled:
                if temperature.zone in zones:
                    stream_id = zones[temperature.zone]
                    s = py.Stream(stream_id)
                    s.open()
                    ts = timestamp.strftime('%Y-%m-%d %H:%M:%S')
                    s.write(dict(x=ts, y=temperature.actual))
                    s.close()
                else:
                    plotly_logger.debug("Zone %s does not have a stream id, ignoring")

    except Exception, e:
        plotly_logger.error("Plot.ly API error - aborting write\n%s", e)

    if plotly_debugEnabled:
        plotly_logger.debug(debug_text)