예제 #1
0
def update_pie_plot(group):
    return dict(data=[
        go.Pie(labels=[
            legendScatterDict[group][val] for val in dfPokemon[group].unique()
        ],
               values=[
                   len(dfPokemon[dfPokemon[group] == val])
                   for val in dfPokemon[group].unique()
               ])
    ],
                layout=go.Layout(title='Pie Chart Pokemon',
                                 margin={
                                     'l': 160,
                                     'b': 40,
                                     't': 40,
                                     'r': 10
                                 }))
예제 #2
0
def update_scatter_plot(hue, x, y):
    return dict(data=[
        go.Scatter(x=dfPokemon[dfPokemon[hue] == val][x],
                   y=dfPokemon[dfPokemon[hue] == val][y],
                   name=legendScatterDict[hue][val],
                   mode='markers') for val in dfPokemon[hue].unique()
    ],
                layout=go.Layout(title='Scatter Plot Pokemon',
                                 xaxis={'title': x},
                                 yaxis=dict(title=y),
                                 margin={
                                     'l': 40,
                                     'b': 40,
                                     't': 40,
                                     'r': 10
                                 },
                                 hovermode='closest'))
예제 #3
0
def update_category_graph(jenisplot, x, y, stats):
    return dict(
        layout=go.Layout(title='{} Plot Pokemon'.format(jenisplot),
                         xaxis={'title': x},
                         yaxis=dict(title=y),
                         boxmode='group',
                         violinmode='group'),
        data=[
            listGoFunc[jenisplot](x=generateValuePlot('True', x,
                                                      y)['x'][jenisplot],
                                  y=generateValuePlot('True', x, y,
                                                      stats)['y'][jenisplot],
                                  name='Legendary'),
            listGoFunc[jenisplot](x=generateValuePlot('False', x,
                                                      y)['x'][jenisplot],
                                  y=generateValuePlot('False', x, y,
                                                      stats)['y'][jenisplot],
                                  name='Non-Legendary')
        ])
def update_hist_plot(x, hue, std):
    std = int(std)
    if (hue == 'All'):
        return dict(data=[
            go.Histogram(x=dfPokemon[
                (dfPokemon[x] >= (dfPokemon[x].mean() -
                                  (std * dfPokemon[x].std())))
                & (dfPokemon[x] <= (dfPokemon[x].mean() +
                                    (std * dfPokemon[x].std())))][x],
                         name='Normal',
                         marker=dict(color='green')),
            go.Histogram(x=dfPokemon[(dfPokemon[x] <
                                      (dfPokemon[x].mean() -
                                       (std * dfPokemon[x].std())))
                                     | (dfPokemon[x] >
                                        (dfPokemon[x].mean() +
                                         (std * dfPokemon[x].std())))][x],
                         name='Not Normal',
                         marker=dict(color='red'))
        ],
                    layout=go.Layout(
                        title='Histogram {} Stats Pokemon'.format(x),
                        xaxis=dict(title=x),
                        yaxis=dict(title='Count'),
                        height=450,
                        width=1000))
    subtitles = []
    for val in dfPokemon[hue].unique():
        dfSub = dfPokemon[dfPokemon[hue] == val]
        outlierCount = len(
            dfSub[(dfSub[x] < (dfSub[x].mean() - (std * dfSub[x].std())))
                  | (dfSub[x] > (dfSub[x].mean() + (std * dfSub[x].std())))])
        subtitles.append(
            legendScatterDict[hue][val] +
            " ({}% outlier)".format(round(outlierCount / len(dfSub) * 100, 2)))

    fig = tools.make_subplots(rows=rowcolhist[hue]['row'],
                              cols=rowcolhist[hue]['col'],
                              subplot_titles=subtitles)
    uniqueData = dfPokemon[hue].unique().reshape(rowcolhist[hue]['row'],
                                                 rowcolhist[hue]['col'])
    index = 1
    for r in range(1, rowcolhist[hue]['row'] + 1):
        for c in range(1, rowcolhist[hue]['col'] + 1):
            dfSub = dfPokemon[dfPokemon[hue] == uniqueData[r - 1, c - 1]]
            fig.append_trace(
                go.Histogram(
                    x=dfSub[(dfSub[x] >= (dfSub[x].mean() -
                                          (std * dfSub[x].std())))
                            & (dfSub[x] <= (dfSub[x].mean() +
                                            (std * dfSub[x].std())))][x],
                    name='Normal {} {}'.format(hue, uniqueData[r - 1, c - 1]),
                    marker=dict(color='green')), r, c)
            fig.append_trace(
                go.Histogram(
                    x=dfSub[(dfSub[x] <
                             (dfSub[x].mean() - (std * dfSub[x].std())))
                            | (dfSub[x] >
                               (dfSub[x].mean() + (std * dfSub[x].std())))][x],
                    name='Not Normal {} {}'.format(hue, uniqueData[r - 1,
                                                                   c - 1]),
                    marker=dict(color='red')), r, c)
            fig['layout']['xaxis' + str(index)].update(title=x.capitalize())
            fig['layout']['yaxis' + str(index)].update(title='Count')
            index += 1

    if (hue == 'Generation'):
        fig['layout'].update(height=700,
                             width=1000,
                             title='Histogram {} Stats Pokemon'.format(x))
    else:
        fig['layout'].update(height=450,
                             width=1000,
                             title='Histogram {} Stats Pokemon'.format(x))

    return fig