[BUG]: 地图轨迹上的图像层渲染的位置略偏北于坐标所指的位置
作者: aldichollow创建于 2026年9月15日更新于 2026年9月15日
标签bugP3size: 3
A small raster: mostly transparent white, with a 2-row-thick red band painted across the exact middle row. Row 0 is the top of the image (north), matching the coordinate order below. ny, nx = 100, 100 rgba = np.full((ny, nx, 4), 255, dtype=np.uint8) rgba[..., 3] = 160 mid = ny // 2 rgba[mid - 1 : mid + 1, :] = [255, 0, 0, 255] buffer = io.BytesIO() Image.fromarray(rgba).save(buffer, format="PNG") data_uri = "data:image/png;base64," + base64.b64encode(buffer.getvalue()).decode() WEST, SOUTH, EAST, NORTH = 134.5, 32.0, 142.5, 40.5 # Where the red band actually sits, by construction. true_lat = NORTH - (mid + 0.5) / ny * (NORTH - SOUTH) figure = go.Figure() figure.update_layout( map={ "style": "carto-positron", "center": {"lat": (SOUTH + NORTH) / 2, "lon": (WEST + EAST) / 2}, "zoom": 5.2, "layers": [ { "sourcetype": "image", "source": data_uri, "coordinates": [[WEST, NORTH], [EAST, NORTH], [EAST, SOUTH], [WEST, SOUTH]], "opacity": 1.0, "below": "traces", } ] }, width=1200, height=1000, title="Red band should sit on the green line, not above it", ) # A second, independent way of marking the same latitude, so there's something to compare the image against that isn't derived from the image layer itself. figure.add_trace( go.Scattermap( lat=[true_lat, true_lat], lon=[WEST, EAST], mode="lines", line={"color": "green", "width": 2}, showlegend=False, ) )
内容来源: plotly/plotly.js