Heatmap mapbox for displaying weather maps

Is there a simple and efficient way to plot a heatmap (not density) with mapbox please?

I manage to do it using Choroplethmapbox with a custom geojson as shown below. While this works it feels it is harder than it could be, and it is not really efficient (handling the json is slow for very large datasets). It would also be nice to be able to show it as filled contours.

Thanks.

from urllib.request import urlopen
import pandas as pd
import plotly.graph_objects as go


df = pd.read_csv(
    "https://raw.githubusercontent.com/rafa-guedes/data/master/socean-hs.csv",
    dtype={"ind": str}
)

# Geojson made up of 1-deg squares centered at lon,lat points in df
geo = {"type": "FeatureCollection", "features": []}
for ind, row in df.iterrows():
    geo["features"].append({
        "type": "Feature",
        "properties": {},
        "geometry": {
            "type": "Polygon",
            "coordinates": [[
                [row.lon - 0.5, row.lat - 0.5],
                [row.lon + 0.5, row.lat - 0.5],
                [row.lon + 0.5, row.lat + 0.5],
                [row.lon - 0.5, row.lat + 0.5],
                [row.lon - 0.5, row.lat - 0.5]
            ]],
        },
        "id": row.ind,
    })

# Artificial heatmap
fig = go.Figure(data=go.Choroplethmapbox(
    geojson=geo,
    locations=df.ind,
    z=df.hs,
    colorscale="Viridis",
    marker_line_width=0,
    showscale=False,
))
fig.update_layout(
    margin={"r":0, "t":0, "l":0, "b":0},
    mapbox=dict(
        style="carto-positron",
        zoom=2,
        center={"lat": -30, "lon": 150},
    ),
)

fig.show()

I am facing a similar problem. Did you find a solution for this?

No I didn’t dig much further into this