Пример #1
0
def plotTraces(
        plotType, label, traces, title, metadata, layoutOptions, suffix =None
):
    suffix = '' if not suffix else ('-' + suffix)

    url = plotly.plot(
        filename=PlotlyUtils.getPlotlyFilename(
            filename='{}{}'.format(label.replace(' ', '-'), suffix),
            folder=PLOTLY_FOLDER),
        figure_or_data=plotlyGraph.Figure(
            data=plotlyGraph.Data(traces),
            layout=_getLayout(
                metadata=metadata,
                title=title, **layoutOptions)),
        auto_open=False)

    print('{}[{}]: {}'.format(plotType, label, PlotlyUtils.toEmbedUrl(url)))
Пример #2
0
def plotComparison(df, key, label, binCount):

    xMin = df[key].min()
    xMax = df[key].max()

    count = df.shape[0]
    test = np.histogram(
        a=df[key].values,
        bins=np.linspace(xMin, xMax, 512))
    cdf = 100.0*np.cumsum(test[0])/float(count)
    for i in range(len(cdf)):
        if cdf[i] >= 98.0:
            xMax = test[1][i]
            break

    areaTraces = []
    xValues = np.linspace(xMin, xMax, 64)
    areaValues = np.zeros(len(xValues) - 1)

    histTraces = []
    bins = np.linspace(xMin, xMax, int(binCount))

    index = 0
    for sizeClass in PlotConfigs.SIZE_CLASSES:
        color = sizeClass['color']
        dataSlice = df[
            (df['width'] >= sizeClass['range'][0]) &
            (df['width'] < sizeClass['range'][1] )]
        sliceCountLabel = locale.format(
            '%d', int(dataSlice.shape[0]), grouping=True)
        histValues = np.histogram(a=dataSlice[key].values, bins=bins)
        histTraces.append(plotlyGraph.Bar(
            name='%s (%s)' % (sizeClass['name'], sliceCountLabel),
            x=100.0*histValues[1],
            y=histValues[0],
            marker=plotlyGraph.Marker(color=color) ))

        histValues = np.histogram(a=dataSlice[key].values, bins=xValues)
        values = 100.0*(dataSlice.shape[0] - np.cumsum(histValues[0]))/count
        areaValues = np.add(areaValues, values)
        areaTraces.append(plotlyGraph.Scatter(
            name='%s (%s)' % (sizeClass['name'], sliceCountLabel),
            x=100.0*histValues[1],
            y=areaValues,
            mode='lines',
            fill='tozeroy' if index < 1 else 'tonexty',
            line=plotlyGraph.Line(
                width=1.0,
                color=color) ))

        index += 1

    countLabel = locale.format('%d', count, grouping=True)

    data = plotlyGraph.Data(histTraces)
    layout = plotlyGraph.Layout(
        title='Distribution of Track %s Deviations (%s Tracks)' % (
            label, countLabel),
        barmode='stack',
        xaxis=plotlyGraph.XAxis(
            title='Deviation (%)'),
        yaxis=plotlyGraph.YAxis(
            title='Frequency',
            autorange=True))

    url = plotly.plot(
        filename=PlotlyUtils.getPlotlyFilename(
            filename='%s' % label.replace(' ', '-'),
            folder=PLOTLY_FOLDER),
        figure_or_data=plotlyGraph.Figure(data=data, layout=layout),
        auto_open=False)
    print(
        'COMPARE|HIST[%s]' % label,
        'x:(%s, %s)' % (xMin, xMax),
        PlotlyUtils.toEmbedUrl(url))

    expected = []
    for x in xValues:
        expected.append(100.0*(1.0 - (norm.cdf(x) - norm.cdf(-x))))

    areaTraces.append(plotlyGraph.Scatter(
        name='Normal Threshold',
        x=100.0*xValues,
        y=expected,
        mode='lines',
        line=plotlyGraph.Line(
            color='rgba(0, 0, 0, 0.75)',
            dash='dash',
            width=1.0) ))

    data = plotlyGraph.Data(areaTraces)
    layout = plotlyGraph.Layout(
        title=('Inverse Cumulative Distribution of Track ' +
            '%s Deviations (%s Tracks)') % (label, countLabel),
        xaxis=plotlyGraph.XAxis(
            title='Deviation (%)',
            range=[100.0*xMin, 100.0*xMax],
            autorange=False),
        yaxis=plotlyGraph.YAxis(
            title='Cumulative Remainder (%)',
            range=[0, 100],
            autorange=False))

    url = plotly.plot(
        filename=PlotlyUtils.getPlotlyFilename(
            filename='%s-cdf-remainder' % label.replace(' ', '-'),
            folder=PLOTLY_FOLDER),
        figure_or_data=plotlyGraph.Figure(data=data, layout=layout),
        auto_open=False)
    print(
        'COMPARE|AREA[%s]' % label,
        'x:(%s, %s)' % (xMin, xMax),
        PlotlyUtils.toEmbedUrl(url))