在 Plotly 的 Scattermapbox 中缩放标记

Scaling Markers with Zoom in Plotly's Scattermapbox

有谁知道是否可以在 Plotly scattermapbox 可视化中指定一个改变标记大小的映射,因为它会改变缩放级别?我想在 densitymapbox 可视化上叠加一个 scattermapbox 可视化,并让散点图在较大比例下不可见,但在放大时可以看到。

谢谢!

  • 您可以在图层
  • 上指定最小缩放
  • 下面的示例显示了一个密度图框,在放大过去 zoom 4 后被红色标记替换
  • 这在标记和密度项相同的情况下显然有效。如果不同,最好用样本数据更新问题
import plotly.express as px
import pandas as pd
import geopandas as gpd
import shapely.geometry
import json

df = pd.DataFrame(
    data=(
        [
            [32.4087249155, -100.9509696428, "2013-01-01", 1],
            [31.5201976084, -102.1030942593, "2013-01-01", 1],
            [31.434573418, -102.0592907601, "2013-01-01", 1],
            [31.2635930582, -101.95341361, "2013-01-01", 1],
            [31.4287233847, -102.0253840388, "2013-01-01", 1],
            [31.4872286706, -101.5455598032, "2021-01-01", 1],
            [31.5439162579, -101.4833865708, "2021-01-01", 1],
            [31.5439362581, -101.4833065695, "2021-01-01", 1],
            [31.7980713977, -102.0937650441, "2021-01-01", 1],
            [32.02050082, -103.31736372, "2021-01-01", 1],
        ]
    ),
    columns=["Latitude", "Longitude", "Date", "Count"],
)


fig = px.density_mapbox(
    df,
    lat="Latitude",
    lon="Longitude",
    z="Count",
    radius=10,
    zoom=3,
)
# fig = go.Figure(go.Scattermapbox())
fig.update_layout(
    mapbox_layers=[
        {
            # "below": "traces",
            "circle": {"radius": 10},
            "color":"red",
            "minzoom": 4,
            "source": gpd.GeoSeries(
                df.loc[:, ["Longitude", "Latitude"]].apply(
                    shapely.geometry.Point, axis=1
                )
            ).__geo_interface__,
        },
    ],
    mapbox_style="carto-positron",
)