在BokehJS中添加第二个y轴

时间:2016-12-29 15:08:58

标签: javascript bokeh

我一直试图在我的BokehJS图中添加第二个y轴,但似乎无法找到如何正确执行。在python散景中我得到了它的工作,但在JavaScript中似乎工作不同。这是最小的例子,我如何尝试创建和使用第二轴:

        var plt = Bokeh.Plotting;

        // create some data and a ColumnDataSource
        var x = Bokeh.LinAlg.linspace(-0.5, 20.5, 10);
        var y = x.map(function (v) { return v * 0.5 + 3.0; });
        var source = new Bokeh.ColumnDataSource({ data: { x: x, y: y }});

        var p = plt.figure({extra_y_ranges: {"y2": new Bokeh.Range1d({start: -1.5, end: 150})} });
        p.yaxis.axis_label = 'Axis Left';
        p.add_layout(new Bokeh.LinearAxis({ y_range_name: "y2", axis_label: 'Axis Right'}), 'right');

        // add a Line glyph
        var line = new Bokeh.Line({
            x: {field: "x"},
            y: {field: "y"},
            line_color: "#F00",
            line_width: 3
        });

        p.add_glyph(line, source);

        // add a Line glyph
        var line = new Bokeh.Line({
            x: {field: "x"},
            y: {field: "y"},
            line_color: "#FF0",
            line_width: 2,
            y_range_name: "y2"
        });

        p.add_glyph(line, source);

        plt.show(p);

轴显示,但该线仍然使用左轴的坐标。

1 个答案:

答案 0 :(得分:1)

诀窍不是直接将y_range_name属性添加到行中,而是添加到图形中的行的glyph对象:

NameError: global name 'package_resource_viewer' is not defined
相关问题