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

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

项目:pongr    作者:wseaton    | 项目源码 | 文件源码
def win_probability_matrix(matrix_df):
    'returns the win probability matrix plot as a plotly heatmap'

    trace = go.Heatmap(
        z=matrix_df.transpose().values.tolist(),
        x=matrix_df.columns[::-1],
        y=matrix_df.columns[::-1],
        colorscale='Viridis'
    )

    data = [trace]

    layout = go.Layout(
        title='Win Probability Matrix',
        xaxis=dict(title='Loser', ticks=''),
        yaxis=dict(title='Winner', ticks=''),
        height=750
    )

    return offl.plot(dict(data=data, layout=layout), output_type='div')
项目:IRCLogParser    作者:prasadtalasila    | 项目源码 | 文件源码
def csv_heatmap_generator_plotly(in_directory, output_directory, output_file_name):
    """
        Plots heatmaps for all the csv files in the given directory

    Args:
        in_directory (str):  location of input csv files
        output_drectory(str): location to save graph
        output_file_name(str): name of the image file to be saved

    Returns:
        null
    """

    file_list = glob.glob(in_directory+"*.csv")

    for file in file_list:
        csv_data = genfromtxt(file, delimiter=',')

        trace = go.Heatmap(
                z=csv_data,
                x=list(range(48)),
                y=list(range(1, 12)),
                colorscale=[
                [0, 'rgb(255, 255, 204)'],
                [0.13, 'rgb(255, 237, 160)'],
                [0.25, 'rgb(254, 217, 118)'],
                [0.38, 'rgb(254, 178, 76)'],
                [0.5, 'rgb(253, 141, 60)'],
                [0.63, 'rgb(252, 78, 42)'],
                [0.75, 'rgb(227, 26, 28)'],
                [0.88, 'rgb(189, 0, 38)'],
                [1.0, 'rgb(128, 0, 38)']
            ]
        )

        data = [trace]
        layout = go.Layout(title='HeatMap', width=800, height=640)
        fig = go.Figure(data=data, layout=layout)

        py.image.save_as(fig, filename=in_directory+file[file.rfind("/")+1:-4]+'_heatmap.png')
项目:eezzy    作者:3Blades    | 项目源码 | 文件源码
def ml_plot_confusion_matrix(TP, FP, FN, TN, x_axis = ['Predict True',  'Predict False'],
y_axis= ['Predict True',  'Predict False'], plot=True):
    trace = go.Heatmap(z=[[TP, FP], [FN, TN]],
                   x=x_axis,
                   y=y_axis,
                   hoverinfo='x+y+z')
    layout = dict(margin = dict(l=100), width = 500, height=500)
    data=[trace]
    fig = dict(data=data, layout=layout)
    if plot == True: iplot(fig, config={'showLink' : False,
    'displaylogo' : False, 'modeBarButtonsToRemove' : ['sendDataToCloud']})
    else: return trace
项目:lens    作者:ASIDataScience    | 项目源码 | 文件源码
def plot_pairdensity(ls, column1, column2):
    """Plot the pairwise density between two columns.

    This plot is an approximation of a scatterplot through a 2D Kernel
    Density Estimate for two numerical variables. When one of the variables
    is categorical, a 1D KDE for each of the categories is shown,
    normalised to the total number of non-null observations. For two
    categorical variables, the plot produced is a heatmap representation of
    the contingency table.

    Parameters
    ----------
    ls : :class:`~lens.Summary`
        Lens `Summary`.
    column1 : str
        First column.
    column2 : str
        Second column.

    Returns
    -------
    :class:`plotly.Figure`
        Plotly figure containing the pairwise density plot.
    """
    pair_details = ls.pair_details(column1, column2)
    pairdensity = pair_details['pairdensity']

    x = np.array(pairdensity['x'])
    y = np.array(pairdensity['y'])
    Z = np.array(pairdensity['density'])

    if ls.summary(column1)['desc'] == 'categorical':
        idx = np.argsort(x)
        x = x[idx]
        Z = Z[:, idx]

    if ls.summary(column2)['desc'] == 'categorical':
        idx = np.argsort(y)
        y = y[idx]
        Z = Z[idx]

    data = [go.Heatmap(z=Z, x=x, y=y, colorscale=DEFAULT_COLORSCALE)]
    layout = go.Layout(
        title='<i>{}</i> vs <i>{}</i>'.format(column1, column2))
    layout['xaxis'] = {
        'type': pairdensity['x_scale'],
        'autorange': True,
        'title': column1
    }
    layout['yaxis'] = {
        'type': pairdensity['y_scale'],
        'autorange': True,
        'title': column2
    }
    fig = go.Figure(data=data, layout=layout)
    fig.data[0]['showscale'] = False

    return fig
项目:Question-Answering    作者:arianhosseini    | 项目源码 | 文件源码
def gen_heatmap(model_name):

    evaluator, valid_stream, ds = build_evaluator(model_name)
    analysis_path = os.path.join('heatmap_analysis', model_name + ".html")

    out_file = open(analysis_path, 'w')
    out_file.write('<html>')
    out_file.write('<body style="background-color:white">')

    printed = 0;
    for batch in valid_stream.get_epoch_iterator(as_dict=True):

        if batch["context"].shape[1] > 150:
            continue;

        evaluator.initialize_aggregators()
        evaluator.process_batch(batch)
        analysis_results = evaluator.get_aggregated_values()
        q_c_attention = analysis_results["question_context_attention"]

        context_words = [ds.vocab[i]+' '+str(index) for index,i in enumerate(batch["context"][0])]
        question_words = [str(index)+' '+ ds.vocab[i] for index, i in enumerate(batch["question"][0])]
        answer_words = [ds.vocab[i] for i in batch["answer"][0]]

        out_file.write('answer: '+' '.join(answer_words))
        out_file.write('<br>')

        x= context_words
        y= question_words
        z = q_c_attention[0]
        # print z.shape

        data = [
            go.Heatmap(z=z,x=x,y=y,colorscale='Viridis')
        ]
        div = plotly.offline.plot(data,auto_open=False, output_type='div')
        out_file.write(div)
        out_file.write('<br>')
        out_file.write('<br>')

        printed += 1
        if printed >= 20:
            break;


    out_file.write('</body>')
    out_file.write('</html>')
    out_file.close()
    print "done ;)"