コード例 #1
0
ファイル: view.py プロジェクト: paulemms/LCA
    def run_item_clicked(self, item):
        logging.info('Run item %s clicked' % item.text(0))
        output = io.StringIO()
        if item.parent() is not None:
            if item.parent().text(0) == 'Variables':
                cpt = self._concrete_model.find_component(item.text(0))

                # create ggplot
                df = mo.get_entity(cpt)
                if item.text(0) == 'S':
                    ff = pn.ggplot(df, pn.aes('T', item.text(0))) + pn.ggtitle(cpt.doc) +\
                         pn.geom_step(pn.aes(color='States'), direction='hv') + pn.facet_wrap('States')
                elif item.text(0) == 'Q':
                    ff = pn.ggplot(df, pn.aes('T', item.text(0))) + pn.ggtitle(cpt.doc) +\
                         pn.geom_step(pn.aes(color='J'), direction='hv') + pn.facet_grid('J~')
                else:
                    ff = pn.ggplot(df, pn.aes('T', item.text(0))) + pn.ggtitle(cpt.doc) +\
                         pn.geom_step(pn.aes(color='J'), direction='hv') + pn.facet_grid('I~')
                size = self.canvas.size()
                ff += pn.theme(figure_size=(size.width() / 100, size.height() / 100))

                # update to the new figure
                fig = ff.draw()
                self.canvas.figure = fig
                self.canvas.draw()

        output.close()
コード例 #2
0
def test_step():
    p = (ggplot(df, aes('x')) +
         geom_step(aes(y='y'), size=4) +
         geom_step(aes(y='y+2'), color='red',
                   direction='vh', size=4))

    assert p == 'step'
コード例 #3
0
def test_step():
    p = (ggplot(df, aes('x')) +
         geom_step(aes(y='y'), size=4) +
         geom_step(aes(y='y+2'), color='red',
                   direction='vh', size=4))

    assert p == 'step'
コード例 #4
0
def test_step_mid():
    df = pd.DataFrame({'x': range(9), 'y': range(9)})
    p = (ggplot(df, aes('x', 'y'))
         + geom_point(size=4)
         + geom_step(direction='mid', size=2)
         )

    assert p == 'step_mid'
コード例 #5
0
def test_line():
    df2 = df.copy()

    # geom_path plots in given order. geom_line &
    # geom_step sort by x before plotting
    df2['x'] = df['x'].values[::-1]

    p = (ggplot(df2, aes('x')) + geom_path(aes(y='y'), size=4) +
         geom_line(aes(y='y+2'), color='blue', size=4) +
         geom_step(aes(y='y+4'), color='red', size=4))

    assert p == 'path_line_step'
コード例 #6
0
def test_line():
    df2 = df.copy()

    # geom_path plots in given order. geom_line &
    # geom_step sort by x before plotting
    df2['x'] = df['x'].values[::-1]

    p = (ggplot(df2, aes('x')) +
         geom_path(aes(y='y'), size=4) +
         geom_line(aes(y='y+2'), color='blue', size=4) +
         geom_step(aes(y='y+4'), color='red', size=4))

    assert p == 'path_line_step'
コード例 #7
0
sv = scale_predictors(df, predictor='SVC')
# ld = scale_predictors(df, predictor='LDA')
nb = scale_predictors(df, predictor='naive_bayes')
rn = scale_predictors(df, predictor='Random')
ac = scale_predictors(df, predictor='acg_ip_risk')
rf = scale_predictors(df, predictor='RandmForest')
ct = scale_predictors(df, predictor='cheating')

df2 = pd.concat([nb, rn, ac, rf, sv, ct])
# df2 = pd.concat([nb, rn, ac, rf, ct])

print(df2.head(20))
print(df2.describe())
p = pn.ggplot(df2, pn.aes(x='num_examined', y='num_detected', group='classifier', colour='classifier')) +\
    pn.geom_step() +\
    pn.ggtitle("How Many ppl would we need to intervene on to prevent Y hospitalizations?")
    # pn.scales.scale_x_reverse()

p.save(HOME_DIR + 'all_together_d.png', height=8, width=10, units='in', verbose=False)

p2 = pn.ggplot(df2, pn.aes(x='num_examined', y='num_detected', group='classifier', colour='classifier')) +\
    pn.geom_step() +\
    pn.ggtitle("How Many ppl would we need to intervene on to prevent Y hospitalizations?") +\
    pn.xlim(0, 300) + pn.ylim(0, 300)
    # pn.scales.scale_x_reverse()

p2.save(HOME_DIR + 'all_together_trunc.png', height=8, width=10, units='in', verbose=False)


print("Finished!")