【问题标题】:Bokeh Widget distorts plot with tile providerBokeh Widget 使用 tile 提供程序扭曲绘图
【发布时间】:2021-10-13 15:58:25
【问题描述】:

当首先通过给定的小部件更改颜色时,绘图会扭曲。当首先用光标移动地图然后改变颜色时,绘图不会扭曲。这仅在添加平铺背景时发生。因此,问题可能在于绘图的底层投影/CRS 和背景中以某种方式发生变化的图块存在差异(?)。

如果您能够找到问题所在,如果您还可以链接到资源,那就太好了,这样我就可以学习如何更深入地调试。

我的浏览器:Brave(基于 Chromium)

简单的工作示例: 支持bigreddot,因为这个工作示例主要基于他的回答。

from bokeh.layouts import grid
from bokeh.models.widgets.inputs import ColorPicker
from bokeh.sampledata import us_states
from bokeh.plotting import *
from bokeh.tile_providers import get_provider, CARTODBPOSITRON

us_states = us_states.data.copy()

del us_states["HI"]
del us_states["AK"]

# separate latitude and longitude points for the borders
#   of the states.
state_xs = [us_states[code]["lons"] for code in us_states]
state_ys = [us_states[code]["lats"] for code in us_states]

# init figure
p = figure(title="Plotting Points Example: The 5 Largest Cities in Texas", 
           toolbar_location="left", plot_width=1100, plot_height=700)

p.xgrid.grid_line_color = None
p.ygrid.grid_line_color = None

# Draw state lines
p.patches(state_xs, state_ys, fill_alpha=0.0,
    line_color="#884444", line_width=1.5)

#  Latitude and Longitude of 5 Cities
# ------------------------------------
# Austin, TX -------30.26° N, 97.74° W
# Dallas, TX -------32.77° N, 96.79° W
# Fort Worth, TX ---32.75° N, 97.33° W
# Houston, TX ------29.76° N, 95.36° W
# San Antonio, TX --29.42° N, 98.49° W

# Now group these values together into a lists of x (longitude) and y (latitude)
x = [-97.7431, -96.79, -97.33, -95.36, -98.49]
y = [30.26, 32.77, 32.75, 29.76, 29.42] 

# add basemap and labels
tile_provider = get_provider(CARTODBPOSITRON)
p.add_tile(tile_provider)
points = p.circle(x, y, size=8, color='navy', alpha=1)

picker = ColorPicker(title=f"Point Color", color="navy")
picker.js_link("color", points.glyph, "fill_color")

# output to static HTML file
output_file("texas.html")
l = grid([p, picker], ncols=2, sizing_mode="fixed")

# show results
show(l)

通过网格显示不是问题 - 如果您通过以下方式显示绘图也会发生:

show(column([p, picker]))

【问题讨论】:

    标签: python-3.x bokeh


    【解决方案1】:

    here所示,需要添加一个

    p.match_aspect = True
    

    到上面的代码输出之前。这解决了随机变化比率的问题。

    【讨论】:

      猜你喜欢
      • 2011-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-14
      • 2018-09-24
      • 1970-01-01
      • 2010-12-29
      • 1970-01-01
      相关资源
      最近更新 更多