materialsinnovation / pymks

Materials Knowledge System in Python
https://pymks.readthedocs.io/
Other
115 stars 76 forks source link

Add 3D plots to notebooks #479

Open wd15 opened 4 years ago

wd15 commented 4 years ago

Code for plotting correlations with pyvista

import pyvista as pv
import numpy as np

pv.set_plot_theme("document")

data = np.load('corr.npy')
print(data.shape)
values = data[0, :22, :22, :22, 4]

# Create the spatial reference
grid = pv.UniformGrid()

# Set the grid dimensions: shape + 1 because we want to inject our values on
#   the CELL data
grid.dimensions = np.array(values.shape) + 1

# Edit the spatial reference
grid.origin = (100, 33, 55.6)  # The bottom left corner of the data set
grid.spacing = (1, 1, 1)  # These are the cell sizes along each axis

# Add the data values to the cell data
grid.cell_arrays["values"] = values.flatten(order="F")  # Flatten the array!

grid.plot(show_edges=False, cmap='jet', show_axes=False, show_scalar_bar=False, off_screen=True, screenshot='corr1.png')

#grid.plot(show_edges=False, show_axes=False, show_scalar_bar=False)
wd15 commented 4 years ago

Code for plotting the microstructure with a gray scale:

import pyvista as pv
import numpy as np

pv.set_plot_theme("document")

values = np.linspace(0, 10, 1000).reshape((20, 5, 10))

data = np.load('3d.npy')
print(data.shape)
print(values.shape)
values = data[9]

# Create the spatial reference
grid = pv.UniformGrid()

# Set the grid dimensions: shape + 1 because we want to inject our values on
#   the CELL data
grid.dimensions = np.array(values.shape) + 1

# Edit the spatial reference
grid.origin = (100, 33, 55.6)  # The bottom left corner of the data set
grid.spacing = (1, 1, 1)  # These are the cell sizes along each axis

# Add the data values to the cell data
grid.cell_arrays["values"] = values.flatten(order="F")  # Flatten the array!

# Now plot the grid!
# import ipdb; ipdb.set_trace()
# pv.remove_scalar_bar()

# plotter = pv.Plotter(off_screen=True)
# plotter.add_mesh(grid)#,
# import ipdb; ipdb.set_trace()
# plotter.show(screenshot='plot1.png', show_edges=False)
grid.plot(show_edges=False, cmap=['black', 'grey', 'white'], show_axes=False, show_scalar_bar=False, off_screen=False, screenshot='plot4.png')