4

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

(如果需要:在 Ubuntu 14.04 上运行 Python 2.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()
4

1 回答 1

5

好的,我需要一个带有一些原型的完整示例trans_dat才能进一步挖掘。不过,这里有一些可能会有所帮助的一般性评论:

x_range并且y_range每个都应该是没有重复的类别列表,按照您希望它们在轴上的顺序。

x并且y应该是您要绘制的每个矩形的分类坐标。x并且y应该是相同的长度。

立即让我感到奇怪的是,您正在传递类别列表和x_2坐标。这通常是一个错误。y_2

假设您有以下类别:

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

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

这些是你可以传递给x_rangeandy_range的。但是,如果您想要每个组合的 rect,那么您需要将这样的内容传递为xand y

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

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

这将产生四个矩形,每对类别一个。如果你想留下一些,那很好:

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

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

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

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

这是否使范围参数(可能的类别列表)和坐标参数(您要在其中绘制字形的类别组合)之间的区别更加清晰?让我知道我是否可以添加更多信息。

于 2014-06-13T15:12:24.047 回答