how to generate easy to share 3d plots?

Member, Employee Posts: 252
50 Answers 100 Comments 100 Likes Second Anniversary
✭✭✭✭
edited June 2023 in 3D Design

You use plotly. This is a test and it needs improvement but the script below generates a 3D plot and saves it to an html.

  1. from ansys.dpf import core as dpf
  2. import numpy as np
  3. import plotly
  4. import plotly.graph_objects as go
  5. import plotly.io as pio
  6. pio.renderers.default='browser'
  7.  
  8.  
  9. myModel = r'set to a small .rst file for testing'
  10.  
  11. ###############
  12. # create dpf's datasource
  13. ds= dpf.DataSources(myModel)
  14. # Get all time points
  15. # Extract model from RST
  16. model=dpf.Model(data_sources=ds)
  17. rst_mesh=model.metadata.meshed_region
  18.  
  19. disp = model.results.displacement().outputs.fields_container()[0]
  20. dispX = np.array(disp.data)[:,0]
  21. dispXNorm = dispX/np.linalg.norm(dispX)
  22. # Get node ids and coordinates from mesh
  23. node_ids = rst_mesh.nodes.scoping.ids
  24. node_coords = rst_mesh.nodes.coordinates_field
  25. node_coords_list = np.array(node_coords.data)#_as_list
  26. x = node_coords_list[:,0]
  27. y = node_coords_list[:,1]
  28. z = node_coords_list[:,2]
  29. fig = go.Figure(data=[go.Mesh3d(x=x, y=y, z=z,
  30. alphahull=5,
  31. opacity=1,
  32. intensity=dispXNorm,
  33. colorscale='rainbow')])
  34. fig.show()
  35. plotly.offline.plot(fig, filename='D:\myPlot.html')

Have to work on the coloring though....

Tagged:

Answers

Welcome!

It looks like you're new here. Sign in or register to get started.