Comments (10)
With this totally unoptimized snippet:
import numpy as np
import pyvista as pv
import csv
from pyvista.utilities import lines_from_points
xfile = open('x_coordinates.csv', 'r')
xreader = csv.reader(xfile, delimiter=',')
x = []
for row in xreader:
x.append(row)
xfile.close()
yfile = open('y_coordinates.csv', 'r')
yreader = csv.reader(yfile, delimiter=',')
y = []
for row in yreader:
y.append(row)
yfile.close()
zfile = open('z_coordinates.csv', 'r')
zreader = csv.reader(zfile, delimiter=',')
z = []
for row in zreader:
z.append(row)
zfile.close()
plotter = pv.Plotter()
plotter.background_color = 'white'
for idx in range(len(x)):
cx = x[idx]
cy = y[idx]
cz = z[idx]
pts = np.column_stack((cx, cy, cz)).astype(np.float)
line = lines_from_points(pts)
plotter.add_mesh(line, show_edges=True)
plotter.show()
Did you expect something similar?
Also, I think it should be possible to append/create an UnstructuredGrid
dataset and use only one call to add_mesh()
. Note that I had to use show_edges=True
to actually visualize the result.
from pyvista-support.
from pyvista-support.
I modified a bit the previous (unoptimized) snippet:
...
plotter = pv.Plotter()
plotter.background_color = 'white'
for idx in range(len(x)):
cx = x[idx]
cy = y[idx]
cz = z[idx]
pts = np.column_stack((cx, cy, cz)).astype(np.float)
lines = lines_from_points(pts)
lines.lines = lines.faces
tube = lines.tube(0.01).elevation()
plotter.add_mesh(tube, show_edges=False)
plotter.show()
The main modifications are lines.lines = lines.faces
which basically updates the lines of the PolyData
required by the tube filter. The rest is pretty straightforward, we apply the filters: first the tube with a radius of 0.01
then the elevation
filter to add a scalar field corresponding to the Z height.
There is maybe a better/efficient way to achieve this, what do you think @pyvista/developers ?
from pyvista-support.
from pyvista-support.
Good start @GuillaumeFavelier!
Here's a little bit of an improvement using splines, which leads to smoother plotting with no breaks along the line.
I'm adding splines to pyvista
for the next release, so you won't need to use make_spline
and will instead use pv.Spline
import numpy as np
import pyvista as pv
x = np.loadtxt('x_coordinates.csv', delimiter=',')
y = np.loadtxt('y_coordinates.csv', delimiter=',')
z = np.loadtxt('z_coordinates.csv', delimiter=',')
def make_spline(points, n_points=None):
"""Create a spline from points
Parameters
----------
points : np.ndarray
Array of points to build a spline out of. Array must be 3D
and directionally ordered.
n_points : int, optional
Number of points to interpolate along the points array.
Returns
-------
spline : pyvista.PolyData
Line mesh of spline.
Examples
--------
Construct a spline
>>> import numpy as np
>>> import pyvista as pv
>>> theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
>>> z = np.linspace(-2, 2, 100)
>>> r = z**2 + 1
>>> x = r * np.sin(theta)
>>> y = r * np.cos(theta)
>>> points = np.column_stack((x, y, z))
>>> spline = pv.Spline(points, 1000)
"""
import vtk
spline = vtk.vtkParametricSpline()
vtk_points = pv.vtk_points(points, False)
spline.SetPoints(vtk_points)
spline.GetPoints().Modified()
spline.Modified()
# get interpolation density
u_res = n_points
if u_res is None:
u_res = points.shape[0]
return pv.geometric_objects.surface_from_para(spline, u_res)
# convert points to splines
splines = []
for idx in range(x.shape[0]):
points = np.column_stack((x[idx], y[idx], z[idx]))
spline = make_spline(points)
# spline = pv.Spline(points) # in the next release
splines.append(spline)
# boring plot
pv.plot(splines)
# exciting plot with scalars
tubes = []
for spline in splines:
# add scalars here...
spline['scalars'] = np.arange(spline.n_points)
tubes.append(spline.tube(0.01))
pv.plot(tubes, smooth_shading=True)
from pyvista-support.
from pyvista-support.
Are you running the latest pyvista?
from pyvista-support.
from pyvista-support.
from pyvista-support.
Not sure what you’re trying to do. Can you provide a code example?
from pyvista-support.
Related Issues (20)
- create uniform mesh HOT 3
- Change the orientation of a scalar bar's title
- Applying textures on models from .obj files HOT 6
- How to create an Unstructured grid from points and faces HOT 2
- Type of data, plotting with glyphs HOT 3
- Controlling the thickness and orientation of a slice in Pyvista HOT 3
- Controlling the image position in window, without any click
- Mask/Remove Voxels in Air (small intersection with surface) HOT 3
- custom slider parameters
- running pyvista on headless machine with Centos OS HOT 1
- Seismic Horizon with Pyvista HOT 8
- Algorithm in sample function?
- Automatically updates HOT 3
- Slow interaction HOT 1
- read from text HOT 4
- Uniform Grid thresholding question HOT 8
- Take data by an input x,y,x coordinate (csv file) from vtk data file HOT 4
- Program broke when creating a mesh using pv.PolyData() HOT 4
- ATTENTION: Please move questions to PyVista's Discussions HOT 1
- plotter.enable_terrain_style not working for me HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyvista-support.