Bokeh中的相关图问题

2024-09-27 21:28:52 发布

您现在位置:Python中文网/ 问答频道 /正文

当我通过rect()(来自Bokeh)绘制数据时,我在可视化中得到一条水平块的单条线。数据打印正确,据我所知格式正确(type()验证了它们都是列表)。有人能诊断吗?如果问题不在这里,那么我可以附加更多的代码。在

(如果需要:在ubuntu14.04上运行python2.7.6)

    from bokeh.plotting import *
    from bokeh.objects import HoverTool, ColumnDataSource
    output_notebook()

    #All the same color just for testing
    colors = [
   "#191919", "#191919", "#191919", "#191919", "#191919", 
    "#191919", "#191919", "#191919", "#191919", "#191919",
    "#191919", "#191919", "#191919", "#191919", "#191919",
    "#191919", "#191919", "#191919", "#191919", "#191919", 
    "#191919", "#191919", "#191919", "#191919", "#191919"
    ]

    x_2 = []
    for i in trans_dat: x_2.append(i)

    y_2 = []
    for i in trans_dat.index: y_2.append(i)

    colors_2 = []
    kwordxstate_2 = []
    for y in y_2:
        for x in x_2:
            kword_state = trans_dat[x][y]
            kwordxstate_2.append(kword_state)
            colors_2.append(colors[kword_state])

    source = ColumnDataSource(
        data = dict(
            x_2=x_2,
            y_2=y_2,
            colors_2=colors_2,
            kwordxstate_2=kwordxstate_2,  
        )
    )

    rect(x_2, y_2, 1,1, source=source,
         x_range=x_2, y_range=y_2,
         color=colors_2, line_color=None,
         tools="resize,hover,previewsave", title="Keywords by state",
         plot_width=900, plot_height=400)

    grid().grid_line_color = None
    axis().axis_line_color = None
    axis().major_tick_line_color = None
    axis().major_label_text_font_size = "10pt"
    axis().major_label_standoff = 0
    xaxis().location = "top"
    xaxis().major_label_orientation = np.pi/3

    show()

Tags: innonesourcetransforlinedatcolor
1条回答
网友
1楼 · 发布于 2024-09-27 21:28:52

好的,我需要一个完整的示例,其中包含一些原型trans_dat,以便进一步挖掘。以下是一些可能有帮助的一般性评论:

x_rangey_range都应该是一个没有重复项的类别列表,按照您希望它们在轴上的顺序排列。在

xy应该是要绘制的每个矩形的分类坐标。x和{}的长度应该相同。在

很快,我觉得奇怪的是,你将x_2和{}传递给两个类别列表,坐标。这通常是个错误。在

假设您有以下类别:

  • x轴:["US", "Canada"]

  • y轴:["Tech", "Agriculture"]

这些是您可以传递给x_rangey_range的内容。但是如果你想要每个组合都有一个rect,那么你需要像这样传递x和{}:

  • x:["US", "US", "Canada", "Canada"]

  • 是:["Tech", Agriculture", "Tech", Agriculture"]

这将产生四个矩形,每对类别对应一个。如果你想漏掉一些,没关系:

  • x:["US", "US", "Canada"]

  • 是:["Tech", Agriculture", Agriculture"]

现在(“加拿大”,“技术”)坐标将没有rect。在

这与数值情况类似:对于x和y轴,我们可能有[0,10]和[1,2]的范围。但是坐标取自这两个范围的乘积,比如(0,1.5)或(5.5,2)。在

这是否使范围参数(可能类别的列表)和坐标参数(您希望在其中绘制图示符的类别的组合)之间的区别更为明确?让我知道如果我可以添加更多的信息。在

相关问题 更多 >

    热门问题