散景返回空地图

时间:2017-07-27 20:08:33

标签: python-3.x data-visualization bokeh data-analysis

我正在尝试创建一个带有bokeh的地图来显示US_cities中的人口,但是一旦我运行代码,它就会返回空地图,框架就在那里但是地图不是。我正在尝试做this之类的事情,但对所有美国城市都这样做。

以下是我在散景数据中使用“us_cities.json”文件的代码:

import pandas as pd

from bokeh.io import show
from bokeh.models import (
    ColumnDataSource,
    HoverTool,
    LogColorMapper
)
from bokeh.palettes import Viridis6 as palette
from bokeh.plotting import figure

palette.reverse()

new_data = pd.read_json("/home/alvin/.bokeh/data/us_cities.json")

#Creating random data that I want to show on map
new_data['pop'] = ((new_data['lat'] * 100) - new_data["lon"])/ 800

#Converting pd series to array 
xs = new_data['lat'].tolist()
ys = new_data['lon'].tolist()
pops = new_data['pop'].tolist()

#creating ColumnDataSource
source = ColumnDataSource(data=dict(
    x=xs,
    y=ys,
    pop = pops,
))

TOOLS = "pan,wheel_zoom,reset,hover,save"

p = figure(
    title="Just a US Map", tools=TOOLS,
    x_axis_location=None, y_axis_location=None
)

color_mapper = LogColorMapper(palette=palette)
p.grid.grid_line_color = None

p.patches('x', 'y', source=source,
          fill_color={'field': 'pop', 'transform': color_mapper},
          fill_alpha=0.7, line_color="white", line_width=0.5)

hover = p.select_one(HoverTool)
hover.point_policy = "follow_mouse"
hover.tooltips = [
    ("population)", "@pop%"),
    ("(Long, Lat)", "($x, $y)"),
]

show(p)

这可能是什么问题?

我正在运行python3和bokeh 0.12.6

如果我查看我的数据,它看起来像这样: enter image description here

1 个答案:

答案 0 :(得分:0)

美国城市数据不包含像县数据一样的字形。您可以显示县数据,并将城市数据覆盖为顶部的散点图:

<input id= "mod" name= "mod" value="<?= $otherSet['mod'] ?>" readonly onclick= "toserve(mod)" />