Black Lives Matter. Please consider donating to Black Girls Code today.

Using Different dataset for Surfacecolor


I’m having trouble changing surface color. I have an elevation surface plot working just fine and I want to overlay data from a different dataset onto the elevation map. The largest problem I see is that the lat and lon coordinate steps on the elevation dataset and the overlay dataset are different.

For instance, If the elevation dataset has lat/lon steps of:
lon(119, 119.01666, … , 121.98333, 122),
lat(21, 21.01666, … , 25.98333, 26)
(step size of 1/60)

and the overlay dataset has lat/lon steps of:
lon(119, 119.0125, … , 121.9875, 122),
lat(21, 21.0125, … , 25.9875, 26)
(step size of 1/80).

Here is what I use in my code:

fig = go.Figure(go.Surface(
    contours = {
        "z": {"show": True, "start": 0.0, "end": 1000.0, "size":1000.0,"color":"black", "highlightwidth": 16}
    z = s,
    surfacecolor= test2["qperr"],
    cmin = 0, cmax = 50)
fig.update_layout(scene=dict(aspectratio=dict(x=1.5, y=2, z=0.25)))

where s is the elevation file as an x,y matrix and test2[“qperr”] is the overlay data in an xarray DataArray.

This first image is the surface it creates:

And this is what the should look like:

I think there is stretching of the overlay dataset. It’s most obvious when we look at where the circular feature is relative to the small islands off the west coast. My current thought process of this is that the code is treating the overlay data grid spacing as being equal to the grid spacing of the elevation map. Meaning a 0.0166 change in lat/lon for elevation will show the data for the 0.0125 change overlay data. That explains why the overlay data is stretched and cut off.

Does anyone know how to get around this? I’m thinking I’d have to interpolate and respace between grid points in the overlay dataset to match the elevation dataset’s grid spacing. It sounds like a huge pain and interpolating is a shunned in my field of work. Is there something that has to be changed in the xarray overlay DataArray or is there something within Plotly that can help me out?

Thanks (and if this has been solved in a separate thread, please direct me to that thread)

Hi @IanCo,

You can plot your dem data, if you evaluate by linear interpolation the values of elevation at the points of the same grid the overlay was defined.

Because you did not provide data I created this example:

Sorry for the late response, but thank you very much! This worked out great