I am new to Mayavi and wrote some code using ChatGPT for 3D representation of resistance measurements taken over a circular sample.
The values are read out locally from a .csv without headers and with data ranging from -10 to +10 for the first to columns and from 1.7 to 125.7 in the third column.
This is the used code:
from mayavi import mlab
import numpy as np
from scipy.interpolate import griddata
# Specify the file path
file_path = r'Some_Path'
# Read the CSV file without specifying column names
df = pd.read_csv(file_path, header=None, na_values='')
# Drop rows with NaN values (you can choose how to handle missing data)
df.dropna(subset=[0, 1, 2], inplace=True)
# Rename columns if needed
df.columns = ["x", "y", "Resistance"]
# Convert the 'Resistance' column to numeric (in case it's not)
df['Resistance'] = pd.to_numeric(df['Resistance'], errors='coerce')
# Determine unique values of 'x' and 'y'
unique_x = df['x'].unique()
unique_y = df['y'].unique()
# Create a regular grid
X, Y = np.meshgrid(unique_x, unique_y)
# Interpolate 'Resistance' values onto the regular grid
points = df[['x', 'y']].values
values = df['Resistance'].values
Z = griddata(points, values, (X, Y), method='linear')
# Create a Mayavi 3D surface plot with automatic warp scaling
mlab.figure(size=(800, 600))
mlab.surf(X, Y, Z, warp_scale="auto")
# Customize the plot (you can adjust the view as needed)
mlab.xlabel('X')
mlab.ylabel('Y')
mlab.zlabel('Resistance')
mlab.view(azimuth=45, elevation=45)
# Show the plot
mlab.show()
I am new to Mayavi and wrote some code using ChatGPT for 3D representation of resistance measurements taken over a circular sample. The values are read out locally from a .csv without headers and with data ranging from -10 to +10 for the first to columns and from 1.7 to 125.7 in the third column. This is the used code:
Sadly the following image is all I can get out