python - 使用 Bokeh 或 ArcPy 标记 map

标签 python bokeh arcgis arcpy

我使用 Bokeh 制作分区统计图并创建其他地理图形,因为 Python 生成它的速度比我用其他方式创建它的速度快一百万倍。

现在我正在做这样的事情:

from bokeh.io import show, output_file, export_png, output_notebook, output_file, save
from bokeh.models import ColumnDataSource, HoverTool, LabelSet
from bokeh.plotting import figure
from bokeh.sampledata.us_counties import data as counties
import pandas as pd

desired_counties=['Franklin County, Ohio','Fairfield County, Ohio']
counties2 = {code: county for code, county in counties.items() if county["detailed name"] in desired_counties}

unemploymentRate = {'Location': desired_counties, 'rate': [100, 100]} #placeholders
df = pd.DataFrame(data=unemploymentRate)

county_xs = [county["lons"] for county in counties2.values()]
county_ys = [county["lats"] for county in counties2.values()]
county_names = [county['name'] for county in counties2.values()]
unemployment = [df.loc[index,'rate'] for county in counties2.values() for index, row in df.iterrows() if df.loc[index,'Location']==county['detailed name']]

source = ColumnDataSource(data=dict(x=county_xs,y=county_ys,name=county_names,rate=unemployment))

TOOLS="hover,save"
p = figure(x_axis_location=None, y_axis_location=None, plot_width=350,plot_height=250,tools=TOOLS)
p.grid.grid_line_color = None
p.outline_line_color = None
p.patches('x', 'y', source=source,
          fill_color='#007a33',
          fill_alpha=1, line_color="black", line_width=3.5)
hover = p.select_one(HoverTool)
hover.point_policy = "follow_mouse"
hover.tooltips = [
    ("Name", "@name"),
    ("Rate","@rate{0.0}%")
]
labels = LabelSet(x='x', y='y', text='name', level='glyph',
          x_offset=0, y_offset=0, source=source, render_mode='css')
p.add_layout(labels)
p.toolbar.logo = None
p.toolbar_location = None
show(p)

这给出了: Image of Franklin and Fairfield counties in Ohio

当我将鼠标悬停在图像上时,我会看到我想要的数据,但我更想要的是图像上注释的数据,而不是打印的可能性。使用 Bokeh 在其文档中提供的 LabelSet 类似乎很完美,除了它适用于 xy 图,因此当尝试在此处使用它时,它只是将标签堆叠在角落中。

问题:

  1. 有人知道如何在不使用外部图形软件的情况下在 Bokeh choropleth 上添加标签吗?
  2. 我有 ArcGIS Pro,它显然可以创建这种类型的 map ,但我正在寻找使用编程来完成此操作的东西。我现在使用 Bokeh,因为我基本上可以告诉它我想要的中心县,并且我编写了代码,使我能够突出显示我想要的县及其周边县的州 map ,创建县/周边县的插图,并在这些县的失业率插图上提供悬停数据(上面的图片/代码是其简化版本)。有没有办法使用 AcrPy/ArcGIS 来解决这个问题?

最佳答案

标签放错位置的原因是您告诉它们使用数据源中的字段“x”和“y”,但数据源没有这些列。您可以计算每个形状的“中心”,并将它们作为 x 和 y 列添加到源中,然后内容就会按照您想要的方式显示。

关于python - 使用 Bokeh 或 ArcPy 标记 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53524785/

相关文章:

python - 在 64 位 linux 机器上运行 32 位 Python 脚本以使用 32 位客户端连接到 oracle DB

python - 在 Bokeh 0.5.0 中,无法指定图表的大小,并且以前的版本出现在同一个输出文件中

javascript - 如何标记以编程方式生成的要素图层?

javascript - onChange 不足以触发 Dojo Combobox 的查询

java - 如何在javafx中使用ArcGis

python - RPi 上的 Raspbian - Python 脚本在 IDLE shell 中运行,但不在 cmd 中运行

javascript - 从javascript返回值到pyqt5

python - 元组列表中两个值之间的差异

python - 有没有办法在 Bokeh 中使用基于文本的 X 值?

python - Bokeh 线图 : How to assign colors when plotting a large number of lines