import numpy as np import plotly.graph_objects as go # # ------------------------- # Load scalar field: x, y, z, value # ------------------------- data = np.loadtxt("./scalar_field.txt") x, y, z, values = data.T # unpack columns # # Create 3D scatter plot # ------------------------- fig = go.Figure(data=go.Scatter3d( x=x, y=y, z=z, mode='markers', marker=dict( size=3, # adjust size of the spheres color=values, # color by scalar value colorscale='Viridis', # or 'Jet', 'Hot', etc. colorbar=dict(title='Scalar Value'), opacity=0.8 ) )) # # Layout options # ------------------------- fig.update_layout( scene=dict( xaxis_title='X', yaxis_title='Y', zaxis_title='Z', aspectmode='data' # maintain aspect ratio ), title="3D Scalar Field", margin=dict(l=0, r=0, b=0, t=50), ) # # Show the figure # ------------------------- fig.show()