英文:
2D section plane through free 3D point data (Python)
问题
好的,这是您要翻译的内容:
"Good day
I have been trying to solve the following problem for two days now. Unfortunately I am not an expert. Still, I allow myself to try to describe my problem here and be thankful for any help.
I have measurement data z (eps_xx
) to specific x and y coordinates. You can see the format represented below as Pandas Dataframe:
Node [-] x [m] y [m] eps_xx [-]
0 1 0.0096 0.0089 8.310000e-07
1 2 0.0000 0.0089 1.317000e-07
2 3 0.0000 0.0000 8.104000e-07
3 4 0.0096 0.0000 2.465000e-06
4 5 0.0192 0.0000 6.276000e-06
... ... ... ... ...
2314 2315 0.7700 0.1333 -7.269000e-06
2315 2316 0.7700 0.1426 -6.697000e-06
2316 2317 0.7700 0.1499 -3.587000e-06
2317 2318 0.7700 0.1520 6.296000e-07
2318 2319 0.7700 0.1600 -2.000000e-06
The points of the x and y coordinates do not follow any pattern and are freely distributed.
I would like to create a 3D surface plot from this data (preferably in plotly but matplolib is also OK). A scatter plot I have already done:
import pandas as pd
import plotly.graph_objects as go
# Read data from Excel file
df = pd.read_excel('Data.xlsx', sheet_name="Step_5")
print(df)
# Extract x, y, z values from data frame
x = df['x [m]'].values
y = df['y [m]'].values
z = df['eps_xx [-]'].values
# Create a 3D scatter plot with the vertical plane
fig = go.Figure()
# Add the scatter plot trace
fig.add_trace(go.Scatter3d(x=x, y=y, z=z, mode='markers', marker=dict(size=3)))
# Set plot layout
fig.update_layout(scene=dict(xaxis_title='x [m]', yaxis_title='y [m]', zaxis_title='eps_xx [-]'))
# Display plot
fig.show()
-
But because the x and y points are freely distributed, the first thing I can't do now is to create a surface plot with
go.Surface(x=x, y=y, z=z)
. -
After I succeed in creating a surface from these 3D measurement points, I would like to generate a 2D plot from it along a given vertical plane. Actually exactly as it can be found in this article:
Wanted Solution like in this article, Picture:
Unfortunately, this article works with functions and not with point measurement data.
- The last step would be to get this new 2D data points of the cutted Plot into a Pandas Dataframe again.
Maybe quite a bit of math needs to be done by hand in the background and just displaying the results in Plotly. In my research so far I only hoped that there is already a prefabricated library for such cutting operations in free 3D space. Linear interpolation can be performed between the data points
I tried already several ways to solve my Problem. I used different libraries like numpy, scipy or scikit-learn and tried various code examples I found. But for 3D point data I really didn't found anything suitable.
Thank you for your help!"
英文:
Good day
I have been trying to solve the following problem for two days now. Unfortunately I am not an expert. Still, I allow myself to try to describe my problem here and be thankful for any help.
I have measurement data z (eps_xx
) to specific x and y coordinates. You can see the format represented below as Pandas Dataframe:
Node [-] x [m] y [m] eps_xx [-]
0 1 0.0096 0.0089 8.310000e-07
1 2 0.0000 0.0089 1.317000e-07
2 3 0.0000 0.0000 8.104000e-07
3 4 0.0096 0.0000 2.465000e-06
4 5 0.0192 0.0000 6.276000e-06
... ... ... ... ...
2314 2315 0.7700 0.1333 -7.269000e-06
2315 2316 0.7700 0.1426 -6.697000e-06
2316 2317 0.7700 0.1499 -3.587000e-06
2317 2318 0.7700 0.1520 6.296000e-07
2318 2319 0.7700 0.1600 -2.000000e-06
The points of the x and y coordinates do not follow any pattern and are freely distributed.
I would like to create a 3D surface plot from this data (preferably in plotly but matplolib is also OK). A scatter plot I have already done:
import pandas as pd
import plotly.graph_objects as go
# Read data from Excel file
df = pd.read_excel('Data.xlsx', sheet_name="Step_5")
print(df)
# Extract x, y, z values from data frame
x = df['x [m]'].values
y = df['y [m]'].values
z = df['eps_xx [-]'].values
# Create a 3D scatter plot with the vertical plane
fig = go.Figure()
# Add the scatter plot trace
fig.add_trace(go.Scatter3d(x=x, y=y, z=z, mode='markers', marker=dict(size=3)))
# Set plot layout
fig.update_layout(scene=dict(xaxis_title='x [m]', yaxis_title='y [m]', zaxis_title='eps_xx [-]'))
# Display plot
fig.show()
-
But because the x and y points are freely distributed, the first thing I can't do now is to create a surface plot with
go.Surface(x=x, y=y, z=z)
. -
After I succeed in creating a surface from these 3D measurement points, I would like to generate a 2D plot from it along a given vertical plane. Actually exactly as it can be found in this article:
Wanted Solution like in this article, Picture:
Unfortunately, this article works with functions and not with point measurement data.
- The last step would be to get this new 2D data points of the cutted Plot into a Pandas Dataframe again.
Maybe quite a bit of math needs to be done by hand in the background and just displaying the results in Plotly. In my research so far I only hoped that there is already a prefabricated library for such cutting operations in free 3D space. Linear interpolation can be performed between the data points
I tried already several ways to solve my Problem. I used different libraries like numpy, scipy or scikit-learn and tried various code examples I found. But for 3D point data I really didn't found anything suitable.
Thank you for your help!
答案1
得分: 0
By luck, a friend came to visit this evening and I was able to ask him. I am therefore posting here the solution that now works for me. Perhaps my request will also be useful for someone else.
The solution for me came with from scipy.interpolate import LinearNDInterpolator
. With this function it is possible to interpolate over the point data Interpolation = LinearNDInterpolator(list(zip(x, y)), z)
.
With the now available function Interpolation
I can calculate the values along an axis existing out of individual points:
for i in range(0, len(x)):
z = Interpolation(x[i], y[i])
At the end I can now display the individual data in a 3D-Plot with plotly (Final result) and have also the data available in the back as dataframes for further calculations.
Thanks a lot for the help anyway. Wish you all successful coding.
英文:
By luck, a friend came to visit this evening and I was able to ask him. I am therefore posting here the solution that now works for me. Perhaps my request will also be useful for someone else.
The solution for me came with from scipy.interpolate import LinearNDInterpolator
. With this function it is possible to interpolate over the point data Interpolation = LinearNDInterpolator(list(zip(x, y)), z)
.
With the now available function Interpolation
I can calculate the values along an axis existing out of individual points:
for i in range(0, len(x)):
z = Interpolation(x[i], y[i])
At the end I can now display the individual data in a 3D-Plot with plotly (Final result) and have also the data aviable in the back as dataframes for further calculations.
Thanks a lot for the help anyway. Wish you all successful coding.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论