Esempio n. 1
0
def compareFileExtViaBarPlots(dictParam, fileNameParam, listParam):
    import plotly.plotly as py
    import plotly.graph_objs as go
    from plotly.graph_objs import Layout, YAxis, Figure, Margin, Font
    import numpy as np
    xList = []
    yList = []
    for it_ in listParam:
        xList.append(it_)
        yList.append(np.mean(dictParam[it_]))

    dataToPlot = [go.Bar(x=xList, y=yList)]
    layoutToUse = Layout(
        title='Distribution of File Types (Average) : ' + fileNameParam,
        titlefont=Font(family='Times New Roman', size=18, color='#000000'),
        yaxis=YAxis(
            showgrid=True,
            showline=True,
            title='Values',
            #range=[0, 35],
            autorange=True,
            titlefont=Font(family='Times New Roman', size=12,
                           color='#000000')),
        width=800,
        height=600,
        margin=Margin(l=140, r=40, b=50, t=80),
    )

    #plot_url = py.plot(dataToPlot, filename=fileNameParam)
    figToPlot = Figure(data=dataToPlot, layout=layoutToUse)
    fileNameParam = "plot-session-info/" + fileNameParam + ".png"
    py.image.save_as(figToPlot, fileNameParam)
Esempio n. 2
0
def plotSharpVSOthers(dictParam, fileNameParam, extOfInterest="cSharpCount"):
    import plotly.plotly as py
    import plotly.graph_objs as go
    from plotly.graph_objs import Layout, YAxis, Figure, Margin, Font
    cSharpList = dictParam[extOfInterest]
    otherList = [100.0 - float(x) for x in cSharpList]
    cSharpTrace_ = go.Box(y=cSharpList, name="C# Files")
    otherTrace_ = go.Box(y=otherList, name="Other Files")
    dataToPlot = [cSharpTrace_, otherTrace_]
    layoutToUse = Layout(
        title='Distribution of File Types : ' + fileNameParam,
        titlefont=Font(family='Times New Roman', size=18, color='#000000'),
        yaxis=YAxis(
            showgrid=True,
            showline=True,
            title='Values',
            #range=[0, 35],
            autorange=True,
            titlefont=Font(family='Times New Roman', size=12,
                           color='#000000')),
        width=800,
        height=600,
        margin=Margin(l=140, r=40, b=50, t=80),
    )

    #plot_url = py.plot(dataToPlot, filename=fileNameParam)
    figToPlot = Figure(data=dataToPlot, layout=layoutToUse)
    fileNameParam = "plot-session-info/" + fileNameParam + ".png"
    py.image.save_as(figToPlot, fileNameParam)
Esempio n. 3
0
def compareViaBoxPlot(posGroupParam, zeroGroupParam, negGroupParam,
                      fileNameParam):
    import plotly.plotly as py
    import plotly.graph_objs as go
    from plotly.graph_objs import Layout, YAxis, Figure, Margin, Font
    #from plotly.graph_objs import Bar, Marker, Data, Layout, XAxis, YAxis, Figure, Margin, Font

    posGroup = go.Box(y=posGroupParam, name='Corr. >= 0.50')
    zeroGroup = go.Box(y=zeroGroupParam, name='Corr. within 0.0 & 0.499')
    negGroup = go.Box(y=negGroupParam, name='Corr. < 0.0')

    layoutToUse = Layout(
        title='Distribution of Three Groups: ' + fileNameParam,
        titlefont=Font(family='Times New Roman', size=18, color='#000000'),
        yaxis=YAxis(
            showgrid=True,
            showline=True,
            title='Values',
            #range=[0, 35],
            autorange=True,
            titlefont=Font(family='Times New Roman', size=12,
                           color='#000000')),
        width=800,
        height=600,
        margin=Margin(l=140, r=40, b=50, t=80),
    )

    dataToPlot = [posGroup, zeroGroup, negGroup]
    #plot_url = py.plot(dataToPlot, filename=fileNameParam)
    figToPlot = Figure(data=dataToPlot, layout=layoutToUse)
    fileNameParam = "plots/" + fileNameParam + ".png"
    py.image.save_as(figToPlot, fileNameParam)
Esempio n. 4
0
def plotTwoGroups(group1Param, group2Param, yAxisParam, titleParam,
                  fileNameParam):
    import plotly.plotly as py
    import plotly.graph_objs as go
    from plotly.graph_objs import Layout, YAxis, Figure, Margin, Font

    group1Trace_ = go.Box(y=group1Param, name="High Productivity Sessions")
    group2Trace_ = go.Box(y=group2Param, name="Low Productivity Sessions")
    dataToPlot = [group1Trace_, group2Trace_]
    layoutToUse = Layout(
        title='Summary of 84030 Sessions  : ' + titleParam,
        titlefont=Font(family='Times New Roman', size=18, color='#000000'),
        yaxis=YAxis(
            showgrid=True,
            showline=True,
            title=yAxisParam,
            #range=[0, 35],
            autorange=True,
            titlefont=Font(family='Times New Roman', size=12,
                           color='#000000')),
        width=800,
        height=600,
        margin=Margin(l=140, r=40, b=50, t=80),
    )

    figToPlot = Figure(data=dataToPlot, layout=layoutToUse)
    fileNameParam = "plot-session-info/" + fileNameParam + ".png"
    py.image.save_as(figToPlot, fileNameParam)
    return "DONE!"
Esempio n. 5
0
    def plotConfusionMatrix(self, dataFrame, name):
        """
    @param data         (pandas DF)     The confusion matrix.
    @param name         (str)
    """
        labels = dataFrame.columns.values.tolist()
        values = map(list, dataFrame.values)

        data = Data(
            [Heatmap(z=values, x=labels, y=labels, colorscale='YIGnBu')])

        layout = Layout(
            title='Confusion Matrix for ' + name,
            xaxis=XAxis(title='',
                        side='top',
                        titlefont=Font(family='Courier New, monospace',
                                       size=18,
                                       color='#7f7f7f')),
            yaxis=YAxis(title='',
                        titlefont=Font(family='Courier New, monospace',
                                       size=18,
                                       color='#7f7f7f'),
                        autorange='reversed'),
            barmode='overlay',
            autosize=True,
            width=1000,
            height=1000,
            margin=Margin(l=80, r=80, b=120, t=140))

        fig = Figure(data=data, layout=layout)
        plot_url = py.plot(fig)
        print "Confusion matrix URL: ", plot_url
Esempio n. 6
0
def compareFileExtViaBoxPlots(dictParam, fileNameParam, extList):
    import plotly.plotly as py
    import plotly.graph_objs as go
    from plotly.graph_objs import Layout, YAxis, Figure, Margin, Font
    #from plotly.graph_objs import Bar, Marker, Data, Layout, XAxis, YAxis, Figure, Margin, Font
    dataToPlot = []
    for it_ in extList:
        trace_ = go.Box(y=dictParam[it_], name=it_)
        dataToPlot.append(trace_)

    layoutToUse = Layout(
        title='Distribution of File Types : ' + fileNameParam,
        titlefont=Font(family='Times New Roman', size=18, color='#000000'),
        yaxis=YAxis(
            showgrid=True,
            showline=True,
            title='Values',
            #range=[0, 35],
            autorange=True,
            titlefont=Font(family='Times New Roman', size=12,
                           color='#000000')),
        width=800,
        height=600,
        margin=Margin(l=140, r=40, b=50, t=80),
    )

    #plot_url = py.plot(dataToPlot, filename=fileNameParam)
    figToPlot = Figure(data=dataToPlot, layout=layoutToUse)
    fileNameParam = "plot-session-info/" + fileNameParam + ".png"
    py.image.save_as(figToPlot, fileNameParam)
Esempio n. 7
0
def plotDistForThreeGroups(group1, group2, group3, fileNameParam):
    import plotly.plotly as py
    import plotly.graph_objs as go
    from plotly.graph_objs import Layout, YAxis, Figure, Margin, Font
    #from plotly.graph_objs import Bar, Marker, Data, Layout, XAxis, YAxis, Figure, Margin, Font
    dataToPlot = []
    g1Trace_ = go.Box(y=group1, name="Corr >=0.50")
    g2Trace_ = go.Box(y=group2, name="Corr >=0.0 AND Corr <=0.499")
    g3Trace_ = go.Box(y=group3, name="Corr < 0.0")
    dataToPlot = [g1Trace_, g2Trace_, g3Trace_]
    layoutToUse = Layout(
        title='Distribution of : ' + fileNameParam,
        titlefont=Font(family='Times New Roman', size=18, color='#000000'),
        yaxis=YAxis(
            showgrid=True,
            showline=True,
            title='Values',
            #range=[0, 35],
            autorange=True,
            titlefont=Font(family='Times New Roman', size=12,
                           color='#000000')),
        width=800,
        height=600,
        margin=Margin(l=140, r=40, b=50, t=80),
    )

    #plot_url = py.plot(dataToPlot, filename=fileNameParam)
    figToPlot = Figure(data=dataToPlot, layout=layoutToUse)
    fileNameParam = "plot-session-info/" + fileNameParam + ".png"
    py.image.save_as(figToPlot, fileNameParam)
Esempio n. 8
0
def init_plotly():
    """
    Prepares authenticate tokens for each trace, prepares layout and streams with corresponding scatter graph traces.

    :return: Returns initialized stream IDs for each trace
    """
    logger = logging.getLogger(sys._getframe().f_code.co_name)

    # pull in Plotly authentication data
    plotly_creds = plotly.tools.get_credentials_file()
    username = plotly_creds['username']
    api_key = plotly_creds['api_key']
    token_cpu, token_temp, token_humidity, token_pressure, token_wu = plotly_creds['stream_ids'][0:5]

    plotly.plotly.sign_in(username, api_key)

    # create Stream structures with proper tokens and maximum preserved graph points
    my_stream_cpu = Stream(token=token_cpu, maxpoints=MAX_POINTS)
    my_stream_temp = Stream(token=token_temp, maxpoints=MAX_POINTS)
    my_stream_humidity = Stream(token=token_humidity, maxpoints=MAX_POINTS)
    my_stream_pressure = Stream(token=token_pressure, maxpoints=MAX_POINTS)
    my_stream_wu = Stream(token=token_wu, maxpoints=MAX_POINTS)

    # create Scatter-type structures with appropriate names; don't provide sample data as we'll provide it live in
    # Stream mode
    my_scatter_cpu = Scatter(x=[], y=[], stream=my_stream_cpu, name='CPU temperature', mode=TRACE_MODE)
    my_scatter_temp = Scatter(x=[], y=[], stream=my_stream_temp,
                              name='Environment temperature', mode=TRACE_MODE)
    my_scatter_humidity = Scatter(x=[], y=[], stream=my_stream_humidity,
                                  name='Environment humidity', mode=TRACE_MODE)
    my_scatter_pressure = Scatter(x=[], y=[], stream=my_stream_pressure,
                                  name='Barometric pressure', yaxis='y2',
                                  mode=TRACE_MODE)
    my_scatter_wu = Scatter(x=[], y=[], stream=my_stream_wu, name='Outdoor temperature (Weather Underground)',
                            mode=TRACE_MODE)

    # prepare Data structure
    my_data = Data([my_scatter_cpu, my_scatter_temp, my_scatter_humidity,
                    my_scatter_pressure, my_scatter_wu])

    # create Layout structure where we have one shared X axis (time series) and two Y axis, one left side (temperature
    # and humidity) and one right side (pressure)
    my_layout = Layout(title='Raspberry PI Sensors',
                       xaxis=XAxis(title='Time'), yaxis=YAxis(title='Temperature [C] / Humidity [%]'),
                       yaxis2=YAxis(title='Pressure [hPa]',
                                    overlaying='y', side='right',
                                    titlefont=Font(color='rgb(148, 103, 189)'),
                                    tickfont=Font(color='rgb(148, 103, 189)')))

    # prepare Figure structure
    my_fig = Figure(data=my_data, layout=my_layout)

    try:
        # overwrite existing data on creating the new figure
        plotly.plotly.plot(my_fig, filename=PLOTLY_CHART_NAME, auto_open=False, fileopt=GRAPH_MODE)
    except requests.exceptions.ConnectionError, e:
        logger.error('Cannot connect to PlotLy to create chart: %s. Exiting...' % e)
        sys.exit(1)
Esempio n. 9
0
def scatter_df_plotly(df,
                      x,
                      y,
                      z,
                      text_fnct=hover_all,
                      streaming=True,
                      filename=None):
    """
    a wrapper function for `plotlyi.graph_objs.Scatter` on `pandas.Dataframe`

    usage:
    =====
    d

    """
    layout = Layout(
        title='colour map: %s' % z,
        hovermode='closest',  # (!) hover -> closest data pt
        showlegend=False,  # remove legend (info in hover)
        autosize=False,  # turn off autosize
        width=650,  # plot width
        height=500,  # plot height
        xaxis=XAxis(title=x,
                    titlefont=Font(family='Courier New, monospace',
                                   size=14,
                                   color='#7f7f7f')),
        yaxis=YAxis(title=y,
                    titlefont=Font(family='Courier New, monospace',
                                   size=14,
                                   color='#7f7f7f')))
    #    print('marker sizes:')
    #    print(rescale_marker(df[z], square = True))
    SC = Scatter(x=df[x],
                 y=df[y],
                 mode='markers',
                 marker=Marker(size=rescale_marker(df[z], square=True),
                               color=df[z],
                               colorscale='Jet',
                               sizeref=1,
                               sizemode='area'))

    FIG = Figure(data=Data([SC]), layout=layout)
    #FIG['layout'].update( )

    if text_fnct is not None:
        FIG['data'][0].update(text = \
        df.apply(lambda ds: text_fnct(ds, x=x, y=y,z=z), axis = 1).tolist()  )

    if not streaming:
        if filename is not None:
            return py.plot(FIG, filename=filename)
        else:
            return py.plot(FIG)
    else:
        return py.iplot(FIG)
Esempio n. 10
0
 def new_canvas(self,
                figure=None,
                row=1,
                col=1,
                projection='2d',
                xlabel=None,
                ylabel=None,
                zlabel=None,
                title=None,
                xlim=None,
                ylim=None,
                zlim=None,
                **kwargs):
     #if 'filename' not in kwargs:
     #    print('PlotlyWarning: filename was not given, this may clutter your plotly workspace')
     #    filename = None
     #else:
     #    filename = kwargs.pop('filename')
     if figure is None:
         figure = self.figure(is_3d=projection == '3d')
         figure.layout.font = Font(family="Raleway, sans-serif")
     if projection == '3d':
         figure.layout.legend.x = .5
         figure.layout.legend.bgcolor = '#DCDCDC'
     return (figure, row, col), kwargs
Esempio n. 11
0
def plot_ly(subgraph, title, data, measure, colorscale='Hot'):
    '''
    Function to get a plotly figure object to be plotted
    Args:
        subgraph (NetworkX Graph): the graph to be plotted
        title (str): the title for the plot
        data (dict): the measured data to be plotted
        measure (str): the measure being plotted
        colorscale (str): colorscale for the data measure
        ColorScale options
        'Greys' | 'Greens' | 'Bluered' | 'Hot' | 'Picnic' | 'Portland' |
        Jet' | 'RdBu' | 'Blackbody' | 'Earth' | 'Electric' | 'YIOrRd' |
        'YIGnBu'
    '''
    pos = nx.spring_layout(subgraph, k=.12)
    nodes = list(subgraph.node.keys())
    nodes.sort()
    labels = []
    for node in subgraph.nodes():
        author_name = subgraph.node[node]['data']['author']['name'].title()
        label = "{}<br>{} = {}".format(author_name, measure, str(data[node]))
        labels.append(label)
    trace1 = scatter_edges(subgraph, pos)
    trace2 = scatter_nodes(pos=pos,
                           labels=labels,
                           title=title,
                           data=data,
                           nodes=nodes,
                           colorscale=colorscale)
    width = 800
    height = 600
    axis = dict(showline=False,
                zeroline=False,
                showgrid=False,
                showticklabels=False,
                title='')
    layout = Layout(title=title,
                    font=Font(),
                    showlegend=False,
                    autosize=False,
                    width=width,
                    height=height,
                    xaxis=dict(title='',
                               titlefont=dict(size=14, color='#7f7f7f'),
                               showline=False,
                               showticklabels=False,
                               zeroline=False),
                    yaxis=YAxis(axis),
                    margin=Margin(
                        l=40,
                        r=40,
                        b=85,
                        t=100,
                        pad=0,
                    ),
                    hovermode='closest',
                    plot_bgcolor='#EFECEA')
    data = Data([trace1, trace2])
    fig = Figure(data=data, layout=layout)
    return fig
def make_sbplt_anno(sbplt_in, x_in, y_in, name):
    return Annotation(x=np.mean(x_in),
                      y=y_in[-1],
                      text=name,
                      xanchor='center',
                      align='center',
                      font=Font(size=14),
                      showarrow=False,
                      xref='x{}'.format(sbplt_in),
                      yref='y{}'.format(sbplt_in))
def make_score_anno(sbplt_in, x_in, y_in, score):
    return Annotation(
        x=x_in.max() - 0.95,  # had to tweak these from
        y=y_in.min() + 0,  #  from original
        text=('%.2f' % score).lstrip('0'),
        align='right',
        font=Font(size=15),
        showarrow=False,
        xref='x{}'.format(sbplt_in),
        yref='y{}'.format(sbplt_in))
Esempio n. 14
0
    def plotBucketsMetrics(self, metricsDict, comboMethod, numIterations,
                           modelName):
        """
    @param metricsDicts   (dict)  Arrays for the min, mean, and max of each
                                  metric.
    @param comboMethod    (str)   Concatenation method from the experiment.
    @param numIterations  (str)   Number of inference steps run.
    @param modelName      (str)   Name of tested model.
    """
        xData = range(1, numIterations + 1)

        for metricName, results in metricsDict.iteritems():
            if metricName == "totalRanked": continue
            minTrace = Scatter(x=xData,
                               y=results[0],
                               mode="lines+markers",
                               name="min")
            meanTrace = Scatter(x=xData,
                                y=results[1],
                                mode="lines+markers",
                                name="mean")
            maxTrace = Scatter(x=xData,
                               y=results[2],
                               mode="lines+markers",
                               name="max")
            data = [minTrace, meanTrace, maxTrace]

            layout = Layout(
                title="Buckets Experiment for {} ('{}' concatenation) ".format(
                    modelName, comboMethod),
                xaxis=XAxis(title="Number of samples queried",
                            titlefont=Font(family='Courier New, monospace',
                                           size=18,
                                           color='#7f7f7f'),
                            dtick=1),
                yaxis=YAxis(title=metricName,
                            titlefont=Font(family='Courier New, monospace',
                                           size=18,
                                           color='#7f7f7f')))

            fig = Figure(data=data, layout=layout)
            plotUrl = py.plot(fig)
            print "Plot URL for {}: {}".format(metricName, plotUrl)
Esempio n. 15
0
    def plotConfusionMatrix(self, data, normalize=True):
        """
    Plots the confusion matrix of the input dataframe.
    
    @param data         (pandas DF)     The confusion matrix.

    @param normalize    (bool)          True will normalize the confusion matrix
        values for the total number of actual classifications per label. Thus
        the cm values are 0.0 to 1.0.
    """
        xyzData = self.interpretConfusionMatrixData(data, normalize)

        data = Data([
            Heatmap(z=xyzData["z"],
                    x=xyzData["x"],
                    y=xyzData["y"],
                    colorscale='YIGnBu')
        ])

        layout = Layout(
            title='Confusion matrix for ' + self.experimentName,
            xaxis=XAxis(title='Predicted label',
                        side='top',
                        titlefont=Font(family='Courier New, monospace',
                                       size=18,
                                       color='#7f7f7f')),
            yaxis=YAxis(title='True label',
                        titlefont=Font(family='Courier New, monospace',
                                       size=18,
                                       color='#7f7f7f'),
                        autorange='reversed'),
            barmode='overlay',
            autosize=True,
            width=1000,
            height=1000,
            margin=Margin(l=200, r=80, b=80, t=450))

        fig = Figure(data=data, layout=layout)
        plot_url = py.plot(fig)
        print "Confusion matrix URL: ", plot_url
Esempio n. 16
0
    def plotCumulativeAccuracies(self, classificationAccuracies, trainSize):
        """
    Creates scatter plots that show the accuracy for each category at a
    certain training size
    
    @param classificationAccuracies (dict)    Maps a category label to a list of
        lists of accuracies. Each item in the key is a list of accuracies for
        a specific training size, ordered by increasing training size.
        
    @param trainSize                (list)    Sizes of training sets for trials.
    """
        # Convert list of list of accuracies to list of means
        classificationSummaries = [
            (label, map(numpy.mean, acc))
            for label, acc in classificationAccuracies.iteritems()
        ]

        data = []
        sizes = sorted(set(trainSize))
        for label, summary in classificationSummaries:
            data.append(Scatter(x=sizes, y=summary, name=label))
        data = Data(data)

        layout = Layout(
            title='Cumulative Accuracies for ' + self.experimentName,
            xaxis=XAxis(title='Training size',
                        titlefont=Font(family='Courier New, monospace',
                                       size=18,
                                       color='#7f7f7f')),
            yaxis=YAxis(title='Accuracy',
                        titlefont=Font(family='Courier New, monospace',
                                       size=18,
                                       color='#7f7f7f')))

        fig = Figure(data=data, layout=layout)
        plot_url = py.plot(fig)
        print "Cumulative Accuracies URL: ", plot_url
Esempio n. 17
0
def create_annotations():
    timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    anno_text = 'time: {0}'.format(timestamp)
    annotations = [
        dict(
            text=anno_text,  # set annotation text
            showarrow=False, # remove arrow 
            xref='paper',  # use paper coords
            yref='paper',  #  for both coordinates
            x=0.95,  # position's x-coord
            y=1.10,  #   and y-coord
            font=Font(size=16),    # increase font size (default is 12)
            bgcolor='#FFFFFF',     # white background
            borderpad=4            # space bt. border and text (in px)
        )
    ]
    return annotations
Esempio n. 18
0
def draw_graph(word, hypernym=False):
    """Draw graph of word hyponym, or hypernym if hypernym=True,
    Displays in Jupyter notebook.
    Requires pre-installed plotly apikey"""
    G = visualize_word(word, not hypernym)
    nxpos = nx.fruchterman_reingold_layout(G)
    labels = []
    pos = []
    for k, v in nxpos.items():
        labels.append(str(k()))
        pos.append(v)
    trace1 = scatter_edges(G, nxpos)
    trace2 = scatter_nodes(pos, labels=labels)

    axis = dict(
        showline=False,  # hide axis line, grid, ticklabels and title
        zeroline=False,
        showgrid=False,
        showticklabels=False,
        title='')
    layout = Layout(
        title='Graph for word "{}"'.format(word),
        font=Font(),
        showlegend=False,
        autosize=True,
        # width=width,
        # height=height,
        xaxis=XAxis(axis),
        yaxis=YAxis(axis),
        #margin=Margin(
        #  l=40,
        #  r=40,
        #  b=85,
        #  t=100,
        #  pad=0,),
        # plot_bgcolor='#EFECEA', #set background color
        hovermode='closest')

    data = Data([trace1, trace2])

    fig = Figure(data=data, layout=layout)
    return plotly.iplot(fig, filename='networkx')
Esempio n. 19
0
def make_report_plotly(counts, suffix, report):
    
    for count in counts:
        run_test( report, count )
        
    for category, results in report.iteritems():
        
        #formatter = results['formatter']
        scale = results['scale']
        unit = results['unit']
        
        bars = []
        for name, values in results.iteritems():
            if name in ['title', 'scale', 'unit']:
                continue

            #values = map(formatter, map(lambda x: x * scale, values))
            values = map(lambda x: x * scale, values)

            bar = Bar(  x=counts,
                        y=values,
                        name=name )
            bars.append(bar)
    
        layout = Layout(title=results['title'],
                        font=Font(family='Raleway, sans-serif'),
                        showlegend=True,
                        barmode='group',
                        bargap=0.15,
                        bargroupgap=0.1,
                        legend=Legend(x=0, y=1.0),
                        xaxis=XAxis(title='Num Sites', type='category'),
                        yaxis=YAxis(title=results['unit'])
                        )
        
        data = Data(bars)
        fig = Figure(data=data, layout=layout)
        outpath = '../images/%s%s.png' % (category, suffix)
        py.image.save_as(fig, outpath)
        
        print "Wrote", outpath
Esempio n. 20
0
prediction = slope * (xi[-1]) + intercept

# Creating the dataset, and generating the plot
trace1 = Scatter(x=xi,
                 y=y,
                 mode='lines',
                 marker=Marker(color='rgb(255, 127, 14)'),
                 name='Data')

trace2 = Scatter(x=[xi[-1] + 1],
                 y=[prediction],
                 mode='markers',
                 marker=Marker(color='rgb(31, 119, 180)'),
                 name='Fit')

annotation = Annotation(x=3.5,
                        y=23.5,
                        text='$R^2 = 0.9551,\\Y = 0.716X + 19.18$',
                        showarrow=False,
                        font=Font(size=16))
layout = Layout(title='Linear Fit in Python',
                plot_bgcolor='rgb(229, 229, 229)',
                xaxis=XAxis(zerolinecolor='rgb(255,255,255)',
                            gridcolor='rgb(255,255,255)'),
                yaxis=YAxis(zerolinecolor='rgb(255,255,255)',
                            gridcolor='rgb(255,255,255)'),
                annotations=[annotation])

to_scatter = [trace1, trace2]
plotly.offline.plot({"data": to_scatter, "layout": layout})
Esempio n. 21
0
    def draw_igraph(self, title, colors=None):
        (Xn, Yn, Zn), (Xe, Ye, Ze) = self.get_3d_position()

        trace1 = Scatter3d(x=Xe,
                           y=Ye,
                           z=Ze,
                           mode='lines',
                           line=Line(color='rgb(125,125,125)',
                                     width=1,
                                     dash=True),
                           hoverinfo='none')

        trace2 = Scatter3d(
            x=Xn,
            y=Yn,
            z=Zn,
            mode='markers',
            name='callers',
            marker=Marker(
                symbol='dot',
                size=[100 * x + 5 for x in list(self.betweenness.values())],
                color=self.colors,
                colorscale='Rainbow',
                opacity=0.5),
            text=self.nodes,
            hoverinfo='text')

        axis = dict(showbackground=False,
                    showline=False,
                    zeroline=False,
                    showgrid=False,
                    showticklabels=False,
                    title='')
        layout = Layout(
            title=title,
            width=1000,
            height=1000,
            showlegend=False,
            scene=Scene(
                xaxis=XAxis(axis),
                yaxis=YAxis(axis),
                zaxis=ZAxis(axis),
            ),
            margin=Margin(t=100),
            hovermode='closest',
            annotations=Annotations([
                Annotation(showarrow=False,
                           text="Data source: ???",
                           xref='paper',
                           yref='paper',
                           x=0,
                           y=0.1,
                           xanchor='left',
                           yanchor='bottom',
                           font=Font(size=14))
            ]),
        )

        data = Data([trace1, trace2])
        fig = Figure(data=data, layout=layout)

        iplot(fig, filename='Call Network')
Esempio n. 22
0
import plotly.plotly as py
import plotly.tools as tls
from plotly.graph_objs import Heatmap, Layout, Font

stream_id = tls.get_credentials_file()['stream_ids'][3]

stream = py.Stream(stream_id)
stream.open()

anno_text = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
layout = Layout(annotations=[
    dict(
        text=anno_text,  # set annotation text
        showarrow=False,  # remove arrow
        xref='paper',  # use paper coords
        yref='paper',  # for both coordinates
        x=0.95,  # position's x-coord
        y=1.05,  # and y-coord
        font=Font(size=14),  # increase font size (default is 12)
        bgcolor='#FFFFFF',  # white background
        borderpad=4  # space bt. border and text (in px)
    )
])
x = ['a', 'b', 'c', 'd']
y = ['x', 'y', 'z']
z = np.random.randn(3, 4)
trace = Heatmap(z=z, x=x, y=y)
stream.write(trace, layout=layout)

stream.close()
Esempio n. 23
0
def draw3Dnx(graph=None,
             out_path=None,
             perc_threshold=None,
             positions_array=None,
             positions_dict=None,
             plot_title='',
             plot_description='',
             colorscale='Set3',
             notebook_mode=True,
             auto_open=False):
    """Draws a given graph in 3D"""

    if graph is None or nx.is_empty(graph):
        raise ValueError('input graph can not be empty!')
        # graph = nx.random_geometric_graph(200, 0.05)

    if notebook_mode:
        init_notebook_mode()

    marker_size = 7
    marker_edge_width = 2
    link_width = 2
    colorbar_title = 'Node Connections'
    hover_description = '# connections: '

    position_attr = ['x', 'y', 'z']
    if positions_array is not None:
        for node in graph.nodes():
            for ix, attr in enumerate(position_attr):
                graph.nodes[node][attr] = positions_array[node][ix]
    elif positions_dict is not None:
        for node in graph.nodes():
            for attr in position_attr:
                graph.nodes[node][attr] = positions_array[node][attr]

    for attr in position_attr:
        if not nx.get_node_attributes(graph, attr):
            raise ValueError(
                'Position attribute {} missing. '
                'Add it to graph or supply with one of the position inputs'.
                format(attr))

    edge_threshold = -np.Inf
    if perc_threshold is not None:
        eval_distr = np.array(
            list(nx.get_edge_attributes(graph, 'weight').values()))
        try:
            edge_threshold = np.percentile(eval_distr, perc_threshold)
        except:
            print('threshold to prune edges can not be determined.')
            traceback.print_exc()
            return

    edge_trace = Scatter3d(
        x=[],
        y=[],
        z=[],
        mode='lines',
        line=Line(width=marker_edge_width, color='#888'),
        hoverinfo='none',
    )

    def get_position(gnode):
        """Helper to retun the x, y, z coords of a node"""
        return gnode['x'], gnode['y'], gnode['z']

    for src, dest in graph.edges():
        # adding only the strongest edges
        if perc_threshold is None or graph.get_edge_data(
                src, dest)['weight'] > edge_threshold:
            x0, y0, z0 = get_position(graph.nodes[src])  # ['position']
            x1, y1, z1 = get_position(graph.nodes[dest])  # ['position']
            edge_trace['x'].extend([x0, x1, None])
            edge_trace['y'].extend([y0, y1, None])
            edge_trace['z'].extend([z0, z1, None])

    # empty lists here will be appended with data to be plotted
    node_trace = Scatter3d(x=[],
                           y=[],
                           z=[],
                           text=[],
                           mode='markers',
                           hoverinfo='text',
                           marker=Marker(
                               symbol='dot',
                               showscale=True,
                               colorscale=colorscale,
                               reversescale=True,
                               color=[],
                               size=marker_size,
                               colorbar=dict(thickness=15,
                                             title=colorbar_title,
                                             xanchor='left',
                                             titleside='right'),
                           ))

    # setting nodal positions and info
    for ix, node in enumerate(graph.nodes()):
        x, y, z = get_position(graph.nodes[node])
        node_trace['x'].append(x)
        node_trace['y'].append(y)
        node_trace['z'].append(z)
        node_trace['text'].append(node)
        node_trace['marker']['color'].append(ix)

    axis = dict(showbackground=False,
                showline=False,
                zeroline=False,
                showgrid=False,
                showticklabels=False,
                title='')

    scene = Scene(xaxis=XAxis(axis), yaxis=YAxis(axis), zaxis=ZAxis(axis))

    annotations = Annotations([
        Annotation(
            showarrow=False,
            text=plot_description,
            xref='paper',
            yref='paper',
            x=0,
            y=0.1,  # z=0.05,
            xanchor='left',
            yanchor='bottom',  # zanchor='bottom',
            font=Font(size=14))
    ])

    layout = Layout(
        title=plot_title,
        titlefont=dict(size=16),
        # width=1000,
        # height=1000,
        showlegend=False,
        hovermode='closest',
        scene=scene,
        margin=Margin(t=100),
        # margin=dict(b=20,l=5,r=5,t=40),
        annotations=annotations,
    )

    fig_data = Data([edge_trace, node_trace])

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

    if out_path is None and auto_open is False:
        auto_open = True

    if notebook_mode:
        iplot(fig, filename=out_path)
    else:
        plot(fig, filename=out_path, auto_open=auto_open)

    return fig
Esempio n. 24
0
         showlegend=False,
         scene=Scene(
         xaxis=XAxis(axis),
         yaxis=YAxis(axis),
         zaxis=ZAxis(axis),
        ),
     margin=Margin(
        t=100
    ),
    hovermode='closest',
    annotations=Annotations([
           Annotation(
           showarrow=False,
            text="",
            xref='paper',
            yref='paper',
            x=0,
            y=0.1,
            xanchor='left',
            yanchor='bottom',
            font=Font(
            size=14
            )
            )
        ]),    )

data=Data([trace1, trace2])
fig=Figure(data=data, layout=layout)

py.plot(fig, filename='Crawler')
Esempio n. 25
0
def Generate_3DModel(idList, labelList, percentage):

    network = pd.read_csv("network.csv")
    L = len(network['TF'])

    #Values=[network['importance'][k] for k in range(L)]

    #G=ig.Graph(Edges, directed=False)
    #layt=G.layout('kk', dim=3)

    G = Create_Graph(idList, labelList, percentage, netthreshold)
    N = len(list(G.node()))  #--> Numero de nodos
    V = list(G.node())  # lista con todos los nodos

    #Edges=[(network['TF'][k], network['target'][k]) for k in range(L)]
    Edges = list(G.edges())

    #layt=nx.spectral_layout(G,dim=3)

    #layt=nx.spring_layout(G, dim=3)
    #layt=nx.fruchterman_reingold_layout(G,dim=3)
    #layt=laytdict.values()

    #g=nx.Graph()
    #g.add_nodes_from(V)
    #g.add_edges_from(Edges)

    layt = nx.fruchterman_reingold_layout(G, dim=3)
    #layt = nx.circular_layout(G,scale=10,dim=3)
    #layt=nx.spring_layout(G,dim=3)
    laytN = list(layt.values())

    Xn = [laytN[k][0] for k in range(N)]  # x-coordinates of nodes
    Yn = [laytN[k][1] for k in range(N)]  # y-coordinates
    Zn = [laytN[k][2] for k in range(N)]  # z-coordinates
    Xe = []
    Ye = []
    Ze = []
    for e in Edges:
        Xe += [layt[e[0]][0], layt[e[1]][0],
               None]  # x-coordinates of edge ends
        Ye += [layt[e[0]][1], layt[e[1]][1], None]
        Ze += [layt[e[0]][2], layt[e[1]][2], None]

    trace1 = Scatter3d(x=Xe,
                       y=Ye,
                       z=Ze,
                       mode='lines',
                       line=Line(color='rgb(125,125,125)', width=1),
                       hoverinfo='none')
    trace2 = Scatter3d(x=Xn,
                       y=Yn,
                       z=Zn,
                       mode='markers+text',
                       textposition='top',
                       name='genes',
                       marker=Marker(symbol='dot',
                                     size=6,
                                     color='#6959CD',
                                     colorscale='Viridis',
                                     line=Line(color='rgb(50,50,50)',
                                               width=1)),
                       text=V,
                       hoverinfo='text')

    #for node, adjacencies in enumerate(G.adjacency()):
    #trace2['marker']['color'].append(len(adjacencies))
    #node_info = 'Number of connections: '+str(len(adjacencies))
    #trace2['text'].append(node_info)

    axis = dict(showbackground=False,
                showline=False,
                zeroline=False,
                showgrid=False,
                showticklabels=False,
                title='')

    fig = Figure(data=Data([trace1, trace2]),
                 layout=Layout(
                     title="Network (3D visualization)",
                     width=1000,
                     height=1000,
                     showlegend=False,
                     scene=Scene(
                         xaxis=XAxis(axis),
                         yaxis=YAxis(axis),
                         zaxis=ZAxis(axis),
                     ),
                     margin=Margin(t=100),
                     hovermode='closest',
                     annotations=Annotations([
                         Annotation(showarrow=False,
                                    text="",
                                    xref='paper',
                                    yref='paper',
                                    x=0,
                                    y=0.1,
                                    xanchor='left',
                                    yanchor='bottom',
                                    font=Font(size=14))
                     ]),
                 ))

    py.iplot(fig, filename='networkx3D')
Esempio n. 26
0
 layout=Layout(width=640,
               height=480,
               autosize=False,
               margin=Margin(l=80, r=63, b=47, t=47,
                             pad=0),
               hovermode='closest',
               showlegend=False,
               annotations=Annotations([
                   Annotation(x=0.000997987927565,
                              y=0.996414507772,
                              text='top-left',
                              xref='paper',
                              yref='paper',
                              showarrow=False,
                              align='left',
                              font=Font(size=12.0,
                                        color='#000000'),
                              opacity=1,
                              xanchor='left',
                              yanchor='top'),
                   Annotation(x=0.000997987927565,
                              y=0.00358549222798,
                              text='bottom-left',
                              xref='paper',
                              yref='paper',
                              align='left',
                              showarrow=False,
                              font=Font(size=12.0,
                                        color='#000000'),
                              opacity=1,
                              xanchor='left',
                              yanchor='bottom'),
Esempio n. 27
0
def plotCorrelations(fileNameP, listP):
    import plotly.plotly as py
    #import plotly
    from plotly.graph_objs import Bar, Marker, Data, Layout, XAxis, YAxis, Figure, Margin, Font
    #import plotly.graph_objs as gObjLib
    ### authentication stuff ....
    #py = plotly.plotly(username='******', key='9ebth53cdo')
    #barSize = 5
    fileTrace = [listP[0], listP[1], listP[2]]
    projectTrace = [listP[3], listP[4], listP[5]]
    stateTrace = [listP[6], listP[7], listP[8]]
    namespaceTrace = [listP[9], listP[10], listP[11]]

    fileCorrTrace = Bar(
        x=['Corr. >= 0.50', 'Corr. within 0.0 & 0.499', 'Corr. < 0.0'],
        #x=[ 'Idle', 'System', 'Code', 'Debug', 'Build'],
        y=fileTrace,
        name='FileInterleaving')

    projCorrTrace = Bar(
        x=['Corr. >= 0.50', 'Corr. within 0.0 & 0.499', 'Corr. < 0.0'],
        #x=[ 'Idle', 'System', 'Code', 'Debug', 'Build'],
        y=projectTrace,
        name='ProjetInterleaving')

    nspaceCorrTrace = Bar(
        x=['Corr. >= 0.50', 'Corr. within 0.0 & 0.499', 'Corr. < 0.0'],
        #x=[ 'Idle', 'System', 'Code', 'Debug', 'Build'],
        y=namespaceTrace,
        name='NamespaceInterleaving')

    stateTrace = Bar(
        x=['Corr. >= 0.50', 'Corr. within 0.0 & 0.499', 'Corr. < 0.0'],
        #x=[ 'Idle', 'System', 'Code', 'Debug', 'Build'],
        y=stateTrace,
        name='StateInterleaving')

    #fileCorrTrace['marker'] = Marker(color='blue', size=barSize)
    #projCorrTrace['marker'] = Marker(color='green', size=barSize)
    #nspaceCorrTrace['marker'] = Marker(color='yellow', size=barSize)
    #stateTrace['marker'] = Marker(color='red', size=barSize)
    fileCorrTrace['marker'] = Marker(color='blue')
    projCorrTrace['marker'] = Marker(color='green')
    nspaceCorrTrace['marker'] = Marker(color='yellow')
    stateTrace['marker'] = Marker(color='red')
    dataToPlot = Data(
        [fileCorrTrace, projCorrTrace, nspaceCorrTrace, stateTrace])

    layoutToUse = Layout(
        title='Distribution of Correlation for 339 Datasets : ' + fileNameP,
        titlefont=Font(family='Times New Roman', size=18, color='#000000'),
        barmode='group',
        xaxis=XAxis(showgrid=True,
                    showline=True,
                    title='Interleaving Correlations',
                    titlefont=Font(family='Times New Roman',
                                   size=12,
                                   color='#000000'),
                    tickwidth=1.5),
        yaxis=YAxis(
            showgrid=True,
            showline=True,
            title='Count',
            #range=[0, 35],
            autorange=True,
            titlefont=Font(family='Times New Roman', size=12,
                           color='#000000')),
        width=800,
        height=600,
        margin=Margin(l=140, r=40, b=50, t=80),
    )
    fileToSave = 'plots/' + fileNameP + '.png'
    figToPlot = Figure(data=dataToPlot, layout=layoutToUse)
    py.image.save_as(figToPlot, fileToSave)
Esempio n. 28
0
def plotLinesForBaseline(fileNameParam):
    import csv
    import plotly.plotly as py
    import plotly.graph_objs as go
    from plotly.graph_objs import Layout, YAxis, Figure, Margin, Font, XAxis

    xList = []
    baselineAct = []
    optimizedAct = []
    baselinePass = []
    optimizedPass = []

    fileToRead = open(fileNameParam, "rU")
    try:
        fileReader = csv.reader(fileToRead,
                                delimiter=',',
                                dialect=csv.excel_tab)
        next(fileReader, None)
        for rowVar in fileReader:
            xList.append(rowVar[0])
            baselineAct.append(rowVar[1])
            optimizedAct.append(rowVar[3])
            baselinePass.append(rowVar[2])
            optimizedPass.append(rowVar[4])
    finally:
        fileToRead.close()

    baselineActTrace = go.Scatter(x=xList,
                                  y=baselineAct,
                                  mode='lines+markers',
                                  name='Baseline-Undetected Active Errors')
    optimizedActTrace = go.Scatter(x=xList,
                                   y=optimizedAct,
                                   mode='lines+markers',
                                   name='Optimized-Undetected Active Errors')
    baselinePassTrace = go.Scatter(x=xList,
                                   y=baselinePass,
                                   mode='lines+markers',
                                   name='Baseline-Undetected Passive Errors')
    optimizedPassTrace = go.Scatter(x=xList,
                                    y=optimizedPass,
                                    mode='lines+markers',
                                    name='Optimized-Undetected Passive Errors')
    ActTraces = [baselineActTrace, optimizedActTrace]
    PassTraces = [baselinePassTrace, optimizedPassTrace]
    layout_ActError = Layout(
        title=
        'Comparing Optimized Values with Baseline Values : Undetected Active Errors',
        titlefont=Font(family='Times New Roman', size=18, color='#000000'),
        xaxis=XAxis(showgrid=True,
                    showline=True,
                    title='Iterations of DE',
                    autorange=False,
                    range=[0, 1100],
                    titlefont=Font(family='Times New Roman',
                                   size=12,
                                   color='#000000')),
        yaxis=YAxis(showgrid=True,
                    showline=True,
                    title='Optimized Value',
                    range=[0, 1500],
                    autorange=False,
                    titlefont=Font(family='Times New Roman',
                                   size=12,
                                   color='#000000')),
        width=800,
        height=600,
        margin=Margin(l=140, r=40, b=50, t=80),
    )

    layout_PassError = Layout(
        title=
        'Comparing Optimized Values with Baseline Values : Undetected Passive Errors',
        titlefont=Font(family='Times New Roman', size=18, color='#000000'),
        xaxis=XAxis(showgrid=True,
                    showline=True,
                    title='Iterations of DE',
                    autorange=False,
                    range=[0, 1100],
                    titlefont=Font(family='Times New Roman',
                                   size=12,
                                   color='#000000')),
        yaxis=YAxis(showgrid=True,
                    showline=True,
                    title='Optimized Value',
                    range=[0, 5],
                    autorange=False,
                    titlefont=Font(family='Times New Roman',
                                   size=12,
                                   color='#000000')),
        width=800,
        height=600,
        margin=Margin(l=140, r=40, b=50, t=80),
    )

    fig_UnActErr = Figure(data=ActTraces, layout=layout_ActError)
    fileNameParam = "UnActError.png"
    py.image.save_as(fig_UnActErr, fileNameParam)

    fig_UnPassErr = Figure(data=PassTraces, layout=layout_PassError)
    fileNameParam = "UnPassError.png"
    py.image.save_as(fig_UnPassErr, fileNameParam)

    return "DONE!"
Esempio n. 29
0
 layout=Layout(width=640,
               height=480,
               autosize=False,
               margin=Margin(l=80, r=63, b=47, t=47,
                             pad=0),
               hovermode='closest',
               showlegend=False,
               xaxis1=XAxis(domain=[0.0, 1.0],
                            range=[0.0, 5.0],
                            type='linear',
                            showline=True,
                            ticks='inside',
                            nticks=6,
                            showgrid=False,
                            zeroline=False,
                            tickfont=Font(size=12.0),
                            anchor='y1',
                            side='bottom',
                            mirror='ticks'),
               yaxis1=YAxis(domain=[0.0, 1.0],
                            range=[0.0, 200.0],
                            type='linear',
                            showline=True,
                            ticks='inside',
                            nticks=5,
                            showgrid=False,
                            zeroline=False,
                            tickfont=Font(size=12.0),
                            anchor='x1',
                            side='left',
                            mirror='ticks')))
Esempio n. 30
0
def plotAllStates(fileNameP, dictP):
    import plotly.plotly as py
    from plotly.graph_objs import Bar, Marker, Data, Layout, XAxis, YAxis, Figure, Margin, Font
    #import plotly.graph_objs as gObjLib
    #####
    dirToSave = "plotsesscat/"
    #barSize = 6
    listForNormalTrace = []
    listForHeavyTrace = []
    listForSuperHeavyTrace = []
    allCatList = ['None', 'Idle', 'System', 'Code', 'Debug', 'Build', 'Navi']
    for it_ in allCatList:
        #print "ZZZZZZZ", dictP[it_]
        listForNormalTrace.append(dictP[it_][0])
        listForHeavyTrace.append(dictP[it_][1])
        listForSuperHeavyTrace.append(dictP[it_][2])

    #print "length - Normal ... ", listForNormalTrace
    #print "length - Heavy ... ", listForHeavyTrace
    #print "length - SuperHeavy ... ", listForSuperHeavyTrace
    normalTrace = Bar(
        x=['None', 'Idle', 'System', 'Code', 'Debug', 'Build', 'Navi'],
        #x=[ 'Idle', 'System', 'Code', 'Debug', 'Build'],
        y=listForNormalTrace,
        name='Normal')

    heavyTrace = Bar(
        x=['None', 'Idle', 'System', 'Code', 'Debug', 'Build', 'Navi'],
        #x=[ 'Idle', 'System', 'Code', 'Debug', 'Build'],
        y=listForHeavyTrace,
        name='Heavy')

    superHeavyTrace = Bar(
        x=['None', 'Idle', 'System', 'Code', 'Debug', 'Build', 'Navi'],
        #x=[ 'Idle', 'System', 'Code', 'Debug', 'Build'],
        y=listForSuperHeavyTrace,
        name='Super Heavy')

    normalTrace['marker'] = Marker(color='green')
    heavyTrace['marker'] = Marker(color='yellow')
    superHeavyTrace['marker'] = Marker(color='red')
    dataToPlot = Data([normalTrace, heavyTrace, superHeavyTrace])

    layoutToUse = Layout(
        title='Distribution of Different Session Categories',
        titlefont=Font(family='Times New Roman', size=22, color='#000000'),
        barmode='group',
        xaxis=XAxis(showgrid=True,
                    showline=True,
                    title='Types of Sessions',
                    titlefont=Font(family='Times New Roman',
                                   size=18,
                                   color='#000000'),
                    tickwidth=1.5),
        yaxis=YAxis(
            showgrid=True,
            showline=True,
            title='Count',
            #range=[0, 35],
            autorange=True,
            titlefont=Font(family='Times New Roman', size=18,
                           color='#000000')),
        width=800,
        height=600,
        margin=Margin(l=140, r=40, b=50, t=80),
    )
    fileToSave = dirToSave + fileNameP + '.png'
    figToPlot = Figure(data=dataToPlot, layout=layoutToUse)
    #plot_url = py.plot(figToPlot, filename=fileToSave)
    py.image.save_as(figToPlot, fileToSave)