散景中的相关图问题 [英] Issues with Correlation graphs in Bokeh

查看:57
本文介绍了散景中的相关图问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When I plot my data through rect() (from Bokeh) I get a singular line of horizontal blocks in my visualization. The data prints out correctly and as far as I know formatted correctly (type() verified that they all were lists). Can anyone diagnose this? If the problem is not here then I can append more code.

((如果需要:在Ubuntu 14.04上运行Python 2.7.6)

(If needed: Running Python 2.7.6 on Ubuntu 14.04)

    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()

推荐答案

好的,我需要有一个完整的示例,其中包含一些典型的trans_dat以便进行进一步的挖掘.以下是一些可能有用的一般注释:

OK, I'd need to have a complete example with some prototypical trans_dat to dig further. Here are some general comments that might help, though:

x_rangey_range应该分别是类别的列表,且没有重复项,并按照您希望它们在轴上的顺序排列.

x_range and y_range should each be a list of the categories with no duplicates, in the order you want them on the axis.

xy应该是要绘制的每个矩形的分类坐标. xy的长度应该相同.

x and y should be the categorical coordinates for each rect you want to plot. x and y should be the same length.

立即让我感到奇怪的是,您同时通过了 类别列表,坐标的x_2y_2.这通常是一个错误.

Immediately it strikes me as odd that you are passing x_2 and y_2 for both the list of categories, and the coordinates. This is usually a mistake.

假设您具有以下类别:

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

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

这些是您可以传递给x_rangey_range的内容.但是,如果您想为每个组合使用rect,则需要传递类似xy的内容:

These are what you could pass to x_range and y_range. But if you want a rect for every combination, then you need to pass something like this as x and y:

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

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

这将导致四个rect,每对类别对应一个.如果您想省略一些,那很好:

That would result in four rects, one for each pair of categories. If you want to leave some out, that's fine:

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

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

现在,(加拿大",技术")坐标将不再存在.

Now there will be no rect for the ("Canada", "Tech") coordinate.

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

This is analogous to the numerical case: we might have ranges [0,10] and [1,2] for x and y axes. But coordinates are taken from the product of these two ranges, things like (0, 1.5) or (5.5, 2).

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

Does this make the distinction between the range parameters (which are the list of possible categories) and the coordinate parameters (which are the combinations of categories that you want to plot glyphs at) more clear? Let me know if I can add more info.

这篇关于散景中的相关图问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆