Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用dataset、matplotlib或plotly中的值将颜色投影到三维曲面_Python_Visualization - Fatal编程技术网

Python 使用dataset、matplotlib或plotly中的值将颜色投影到三维曲面

Python 使用dataset、matplotlib或plotly中的值将颜色投影到三维曲面,python,visualization,Python,Visualization,我目前有一个EEG数据集,它有(x,y,z)节点位置和19个节点的信号。我想用python(matplotlib或plotly)绘制3D头部表面,并用不同颜色显示EEG数据的信号。我现在能够得到头部形状的插值,但不知道如何将信号映射到曲面上的颜色。基本上,我希望有一个三维地形图 下面是一个模拟的示例数据和我现在使用的代码。我只想根据Val值更改每个位置的颜色: import pandas as pd import numpy as np import plotly.graph_objects a

我目前有一个EEG数据集,它有(x,y,z)节点位置和19个节点的信号。我想用python(matplotlib或plotly)绘制3D头部表面,并用不同颜色显示EEG数据的信号。我现在能够得到头部形状的插值,但不知道如何将信号映射到曲面上的颜色。基本上,我希望有一个三维地形图

下面是一个模拟的示例数据和我现在使用的代码。我只想根据
Val
值更改每个位置的颜色:

import pandas as pd
import numpy as np
import plotly.graph_objects as go
from scipy.interpolate import NearestNDInterpolator, griddata

plot_df4 = pd.DataFrame([[1, -21, 63, -5],
             [2, 21, 63, -5],
             [3, -53, 31, -8],
             [4, -69, -13, -7],
             [5, -58, -58, -2],
             [6, -40, 42, 33],
              [7, -53, -9, 52],
              [8, -43, -63, 45],
              [9, 0.3, 51, 58],
              [10, 0.3, -7.9, 87],
              [11, 8.583662870175386e-15, -70, 71],
              [12, 46, 48, 36],
              [13,60, -9.7, 56.7],
              [14, 49, -71, 50],
              [15, 67, 41, -10],
              [16, 78, -14, -8.6],
              [17, 67, -67, -2.3],
              [18, -28, -104, 8],
              [19, 28, -105, 8]], columns=["signal", "chan_locax","chan_locay", "chan_locaz"])

np.random.seed(0)
x = plot_df4["chan_locax"]
y = plot_df4["chan_locay"]
z = plot_df4["chan_locaz"]
values = plot_df4["signal"]
X = np.linspace(min(x), max(x))
Y = np.linspace(min(y), max(y))
Z = np.linspace(min(z), max(z))
X, Y, Z = np.meshgrid(X, Y, Z)  # 3D grid for interpolation
interp = NearestNDInterpolator(list(zip(x, y, z)), values)
Val = interp(X, Y, Z)

xi = np.linspace(min(plot_df4["chan_locax"]), max(plot_df4["chan_locax"]), num=100)
yi = np.linspace(min(plot_df4["chan_locay"]), max(plot_df4["chan_locay"]), num=100)

x_grid, y_grid = np.meshgrid(xi, yi)

# Grid data
z_grid = griddata(
    (plot_df4["chan_locax"], plot_df4["chan_locay"]),
    plot_df4["chan_locaz"],
    (x_grid, y_grid),
    method="cubic",
)

# Plotly 3D Surface
fig = go.Figure(go.Surface(x=x_grid, y=y_grid, z=z_grid, colorscale="viridis"))

fig.show()