提问人:GS_1989 提问时间:9/12/2023 最后编辑:GS_1989 更新时间:9/13/2023 访问量:69
Pyvista 挑战,不显示连续缩放和渲染被混淆
Pyvista Challenges, Not Showing Continuous Scale And Rendering is Obfuscated
问:
Pyvista 和 stackoverflow 的新手。
我在使用 Pyvista 的色阶和渲染方面遇到了问题。
以下是代码,大部分是 Pyvista 文档中的样板:
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)
这将创建以下图形:
知道为什么量表是分段的和不正确的吗?
当 show_edges = False 时,我也会遇到奇怪的渲染问题。
此代码也出现了同样的问题:
import pyvista as pv
pv.set_plot_theme(“文件”) 将 numpy 导入为 NP
def plot_grid(): 电网 = 光伏。统一网格()
# 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()
测试函数
plot_grid()
知道为什么在关闭边缘时渲染会被抛出循环吗?
答: 暂无答案
评论
ImageData
UniformGrid
StructuredGrid
print(pv.Report())