Pyvista Challenges, Not Showing Continuous Scale And Rendering is Obfuscated

105 Views Asked by At

Newcomer to Pyvista and stackoverflow.

I'm running into issues with the color scale and rendering using Pyvista.

Here's the code, mostly boilerplate from the Pyvista documentation:

import numpy as np
import pyvista as pv

ni, nj, nk = 4, 5, 20
si, sj, sk = 20, 10, 1

xcorn = np.arange(0, (ni + 1) * si, si)
xcorn = np.repeat(xcorn, 2)
xcorn = xcorn[1:-1]
xcorn = np.tile(xcorn, 4 * nj * nk)

ycorn = np.arange(0, (nj + 1) * sj, sj)
ycorn = np.repeat(ycorn, 2)
ycorn = ycorn[1:-1]
ycorn = np.tile(ycorn, (2 * ni, 2 * nk))
ycorn = np.transpose(ycorn)
ycorn = ycorn.flatten()

zcorn = np.arange(0, (nk + 1) * sk, sk)
zcorn = np.repeat(zcorn, 2)
zcorn = zcorn[1:-1]
zcorn = np.repeat(zcorn, (4 * ni * nj))

corners = np.stack((xcorn, ycorn, zcorn))
corners = corners.transpose()

dims = np.asarray((ni, nj, nk)) + 1
grid = pv.ExplicitStructuredGrid(dims, corners)
grid = grid.compute_connectivity()


cell_centers = grid.cell_centers()
k_values = cell_centers.points[:, 2]
random_values = np.random.rand(grid.n_cells) * k_values
grid.cell_data["values"] = random_values
grid.plot(scalars="values", show_edges=True)

This creates the following graphic:

Scale Issue

Any idea why the scale is segmented and incorrect?

I also run into strange rendering issues when show_edges = False.

Rendering Issue

The same issue arises with this code as well:

import pyvista as pv

pv.set_plot_theme("document") import numpy as np

def plot_grid(): grid = pv.UniformGrid()

# Set the grid dimensions: shape because we want to inject our values
grid.dimensions = [10, 10, 10]

# Edit the spatial reference
grid.origin = [0, 0, 0]  # 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_data["values"] = np.arange(grid.n_cells)

# Now plot the grid!
plotter = pv.Plotter()
plotter.add_mesh(grid, show_edges=True, scalars="values")
plotter.add_scalar_bar(title="Cell Number")
plotter.show()

Test the function

plot_grid()

enter image description here

Any idea why the rendering gets thrown for a loop when the edges are turned off?

0

There are 0 best solutions below