【问题标题】:categorized barchart in bokeh python散景python中的分类条形图
【发布时间】:2018-04-29 06:14:57
【问题描述】:

我正在尝试在散景 python 中绘制 3 级类别,但我遇到了问题并且我的情节不起作用,你能帮我解决这个问题吗?

下面是我的代码:

from bokeh.models import ColumnDataSource, FactorRange
from bokeh.io import show
p = figure(plot_height=250, title="Fruit Counts by Year")

#tp is my data as pandas DataFrame

x1=list(tp['SRN'])
x2=list(tp['SN'])
x3=list(tp['PN'])
counts = list(tp['VS.FEGE.RXMAXSPEED'])
x=[("SRN"+str(a1),"SN"+str(a2),"pN"+str(a3)) for a1,a2,a3 in zip(x1,x2,x3)]
source = ColumnDataSource(data=dict(x=x, counts=counts))
p =figure(x_range=FactorRange(*x),plot_height=250,title="title",toolbar_location=None, tools="")
p.vbar(x='x', top='counts', width=0.9,source=source)
show(p)

tp数据如下:

   SRN  SN  PN  VS.FEGE.RXMAXSPEED  VS.FEGE.TXMAXSPEED
0   0   18  0   1.794           0.307
1   0   18  1   1.896           0.307
2   0   19  0   131238.122      574793.502
3   0   19  1   31806.984       126149.078
4   0   20  0   4.968           0.307

我没有收到任何具体错误,只是没有显示情节。 另外我想知道“x_range=FactorRange(*x)”是如何工作的,有什么替代方法吗?

【问题讨论】:

  • 我不知道为什么有些人不会提供帮助,他们只能投反对票。试了很多遍,找不到原因,也没有3级分类条形图
  • 如果你不能解决它,请至少不要投反对票,让别人帮忙
  • 浏览器 JavaScript 控制台是否有任何输出或错误?
  • 仅使用上面的数据运行代码时,它可以正常工作。所以我不得不怀疑你的完整数据集有问题。你能让它可用吗?如果不是,我只能推测可能是这样的重复因素被创建,这会导致问题。传递给FactorRange 的因子必须是唯一的。

标签: python bar-chart bokeh


【解决方案1】:

从外观上看,您没有导入定义图形的 Bokeh.Plotting。

from bokeh.models import ColumnDataSource, FactorRange
from bokeh.io import show
from bokeh import plotting

p = plotting.figure(plot_height=250, title="Fruit Counts by Year")

无论您在何处使用它,都可以像这样调用“figure”函数。它将解决您的案例中发生的“未定义图形”错误。

【讨论】:

  • 我包括了,这里没提,我的问题是“x_range=FactorRange(*x)”不能正常工作
【解决方案2】:

我发现了问题, 是因为图中重新定义了x_range key参数,如果后面根据数据引用x_range,问题就解决了:

p =figure(x_range=FactorRange(*x),plot_height=250,title="title",toolbar_location=e, tools="")

p.x_range.factors = x

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多