有没有办法覆盖数字或获取散景,python中的图形句柄

时间:2016-10-13 15:18:55

标签: python bokeh figure

我创建了两个散景和蟒蛇并排绘制的数字,然后我创建了另外两个数字。这些现在绘制在前两个之下。我想要的是用新的替换前两个。有没有办法清除旧的并用新的覆盖它们或至少得到它们的句柄?

这是一个简单的例子

# test.py

from bokeh.layouts import Row
from bokeh.layouts import column
from bokeh.plotting import figure, curdoc

# new plots
s1 = figure(title="my data 1", x_axis_label='x', y_axis_label='y')
s2 = figure(title="my data 2", x_axis_label='x', y_axis_label='y')

# my data
x  = [1, 2, 3, 4, 5]
y1 = [1, 2, 3, 4, 5]
y2 = [3, 5, 7, 9, 11]

# plot lines
s1.line(x, y1, legend="data1", line_width=2)
s2.line(x, y2, legend="data2", line_width=3)
p = Row(s1, s2)

curdoc().add_root(column(p))
print "plot 1 done"

# plot lines again
s1 = figure(title="my data 1", x_axis_label='x', y_axis_label='y')
s2 = figure(title="my data 2", x_axis_label='x', y_axis_label='y')
s1.line(x, y1, legend="data1", line_width=2)
s2.line(x, y2, legend="data2", line_width=3)
p = Row(s1, s2)
curdoc().add_root(column(p))
print "plot 2 done"

output

1 个答案:

答案 0 :(得分:0)

我找到了答案。对于这个简单的例子,需要添加

    <?php

$config = [
    'components' => [
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'PJYKlik7HzBS3KA95FBNwr87N9AgeQNg',
        ],
    ],
];

if (!YII_ENV_TEST) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = 'yii\debug\Module';

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = 'yii\gii\Module';
}
if (YII_ENV_DEV) {
    $config['modules']['gii']['generators']['ajax_form_crud_generator'] = [
        'class' => 'alhimik1986\yii2_crud_module\generators\crud\Generator',
        'templates' => [
            'ajax_form_template' => '@vendor/alhimik1986/yii2_crud_module/generators/crud/default',
        ],
    ];
}
return $config;

在第二个curdoc().clear()

之前

如果你想在保持按钮或其他功能存活的同时(因为清除删除所有内容),这里是一个如何处理它的例子:

Dynamically add/remove plot using 'bokeh serve' (bokeh 0.12.0)