Reputation: 21
I am trying to visualize .vtk data using PyVista. I am trying to modify gridlines along the visualized data at specified distances. X axis[0, 5, 10, 15, 20, 25] and Y-axis [0, -1, -2, -3, -4, -5, -6]. From my knowledge in PyVista you can add gridlines using plotter.show_grid, but I am unsure how to modify the grdiss to change the tick mark locations and edit the size of the grid and text. Here is my code:
# Start the virtual frame buffer if needed
pv.start_xvfb()
# Load the .vtk file
file_path = 'Geophysical_Data/Well_Locations/Louse_Creek_Wells/RW01/RW01_Updated.vtk'
mesh = pv.read(file_path)
# Print mesh information and available data arrays
print(mesh)
print("Point data arrays:", mesh.point_data.keys()) # To get the point data array names
print("Cell data arrays:", mesh.cell_data.keys()) # To get the cell data array names
# Print a few sample points to understand the layout
print("Sample points:\n", mesh.points[:10])
# Swap Y and Z coordinates
transformed_points = mesh.points.copy()
transformed_points[:, [1, 2]] = transformed_points[:, [2, 1]] # Swap Y and Z coordinates
# Update the mesh points with the transformed points
mesh.points = transformed_points
# Create a plotter object
plotter = pv.Plotter()
# Visualize the data using 'Resistivity(ohm.m)' array from cell data
plotter.add_mesh(mesh, scalars='Resistivity(ohm.m)', cmap='viridis', clim=[0, 100], scalar_bar_args={'title': 'Resistivity (ohm.m)'})
# Define the start and end points of the vertical line
line_start = np.array([18.5, -0.76, 0]) # Start point (with swapped Y and Z)
line_end = np.array([18.5, -0.76 + 1.13, 0]) # End point extending 1.13m along the X axis
# Create a line by specifying the points
line_points = np.array([line_start, line_end])
# Add the line to the plot using add_lines
plotter.add_lines(line_points, color='black', width=8)
# Set the camera view direction to ensure proper orientation
plotter.view_xy()
# Customize tick locations and labels for the gridlines
plotter.show_grid(
location="outer",
color="black",
xlabel="Distance (m)",
ylabel="Elevation (m)",
zlabel="Elevation (m)"
)
# Show the plot
plotter.show()
# Start the virtual frame buffer if needed
pv.start_xvfb()
# Load the .vtk file
file_path = 'Geophysical_Data/Well_Locations/Louse_Creek_Wells/RW01/RW01_Updated.vtk'
mesh = pv.read(file_path)
# Print mesh information and available data arrays
print(mesh)
print("Point data arrays:", mesh.point_data.keys()) # To get the point data array names
print("Cell data arrays:", mesh.cell_data.keys()) # To get the cell data array names
# Print a few sample points to understand the layout
print("Sample points:\n", mesh.points[:10])
# Swap Y and Z coordinates
transformed_points = mesh.points.copy()
transformed_points[:, [1, 2]] = transformed_points[:, [2, 1]] # Swap Y and Z coordinates
# Update the mesh points with the transformed points
mesh.points = transformed_points
# Create a plotter object
plotter = pv.Plotter()
# Visualize the data using 'Resistivity(ohm.m)' array from cell data
plotter.add_mesh(mesh, scalars='Resistivity(ohm.m)', cmap='viridis', clim=[0, 100], scalar_bar_args={'title': 'Resistivity (ohm.m)'})
# Define the start and end points of the vertical line
line_start = np.array([18.5, -0.76, 0]) # Start point (with swapped Y and Z)
line_end = np.array([18.5, -0.76 + 1.13, 0]) # End point extending 1.13m along the X axis
# Create a line by specifying the points
line_points = np.array([line_start, line_end])
# Add the line to the plot using add_lines
plotter.add_lines(line_points, color='black', width=8)
# Set the camera view direction to ensure proper orientation
plotter.view_xy()
# Customize tick locations and labels for the gridlines
plotter.show_grid(
location="outer",
color="black",
xlabel="Distance (m)",
ylabel="Elevation (m)",
zlabel="Elevation (m)"
)
# Show the plot
plotter.show()
Upvotes: 2
Views: 65