简体   繁体   English

如何在散景中只绘制一个乐队?

[英]How do I plot only a Band in Bokeh?

Bokeh 1.0.1散景 1.0.1

python 3.6.6蟒蛇 3.6.6

I'd like to plot a simple Band using Bokeh.我想使用散景绘制一个简单的乐队。 Here's a minimal example:这是一个最小的例子:

from bokeh.plotting import (output_notebook, figure, show,
        ColumnDataSource)

from bokeh.models import Band

output_notebook()

p = figure()

source = ColumnDataSource({
        'base':[0,1,2,3],
        'lower':[1,2,3,4],
        'upper':[8,6,8,6]
        })

band = Band(base='base', lower='lower', upper='upper', 
            source=source, fill_alpha=0.5)

p.add_layout(band)
#p.scatter(x=[2,3,4], y=[5,6,8])

show(p)

This produces an empty graph (ie, it doesn't plot the Band):这会产生一个空图(即,它不绘制波段): 在此处输入图片说明

There are no errors when running the code.运行代码时没有错误。 BUT if I uncomment the line #p.scatter(x=[2,3,4], y=[5,6,8]) , my band shows up (along with some scatter points that I don't actually want).但是如果我取消注释#p.scatter(x=[2,3,4], y=[5,6,8]) ,我的乐队就会出现(以及一些我实际上不想要的散点) . How can I plot only a Band?我怎样才能只绘制一个乐队?

By default, Bokeh plots have auto-ranges that configure to fit the data.默认情况下,散景图具有配置为适合数据的自动范围。 But that only applies to data glyphs like circle , etc. It does not consider annotations such as Band .但这仅适用于circle等数据字形。它不考虑诸如Band注释。 So when you plot without any glyph, Bokeh does not know what to set the range values to, because there is no glyph data to consider.因此,当您在没有任何字形的情况下绘图时,散景不知道将范围值设置为什么,因为没有要考虑的字形数据。 To plot just a band, you will have to set the ranges explicitly, eg:绘制一个波段,您必须明确设置范围,例如:

p = figure(x_range=(0,5), y_range=(0, 10))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM