Issues with Correlation graphs in Bokeh

泪湿孤枕 提交于 2019-12-10 16:19:16

问题


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.

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

回答1:


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_range and y_range should each be a list of the categories with no duplicates, in the order you want them on the axis.

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

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.

Let's say you have the following categories:

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

  • y-axis: ["Tech", "Agriculture"]

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"]

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.

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.



来源:https://stackoverflow.com/questions/24179776/issues-with-correlation-graphs-in-bokeh

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!