【问题标题】:Plotting on the right axis in Bokeh在散景的右轴上绘图
【发布时间】:2019-09-24 22:52:12
【问题描述】:

我正在构建一个多类别箱线图,但无法将箱线图对齐到正确的位置。

我的基因 x 轴由数据库细分。但是我的情节把所有的东西都画在了基因的中间。

我的轴是这样的:

x = sorted(list(set([(gene, database) for gene in totaldf['gene'].to_list() for database in totaldf['db'].to_list()])))
p = figure(background_fill_color="#efefef", x_range=FactorRange(*x), width=1600, height=700)

我尝试像这样绘制我的盒子:

p.vbar(x=(gene, db), width=0.7, bottom=q2[gene, db], top=q3[gene, db], fill_color="#ffffff", line_color="black")
p.vbar(x=(gene, db), width=0.7, bottom=q1[gene, db], top=q2[gene, db], fill_color="#ffffff", line_color="black")

这导致我的绘图如下所示: https://imgur.com/a/8Q8YC1N

如何将情节放置在正确的位置?数据框如下所示:

      gene       db  mutations
0     IGHV1-3  G1K_CL2          6
1    IGHV1-58  G1K_CL2          2
2    IGHV1-58  G1K_CL2          3
3     IGHV1-8  G1K_CL2          2
4    IGHV3-16  G1K_CL2          3
..        ...      ...        ...
141  IGHV4-61  G1K_CL3         11
142  IGHV4-61  G1K_CL3         12
143  IGHV4-61  G1K_CL3         10
144  IGHV4-61  G1K_CL3         13
145  IGHV7-81  G1K_CL3          4

【问题讨论】:

    标签: python bokeh


    【解决方案1】:

    genedb 是 DataFrame 中的列吗?未以正确的格式提供坐标。您提供的是 2 元组列表,但需要的是 2 元组列表。坐标列表应如下所示:

    x=[(gene1, db1), (gene2, db2), ...])
    

    zip(gene, db) 可能会提供您想要的。

    话虽如此,我还强烈建议在处理嵌套分类数据时使用显式创建的ColumnDataSource。可能会出现一些固有的歧义,而自己构建 CDS 可以消除这些歧义。

    【讨论】:

    • 感谢您的帮助
    猜你喜欢
    • 2016-10-09
    • 2014-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多