Comments (14)
So in brief, the code to make the surface is:
import pandas as pd
import pyvista as pv
# Load Excel sheet using Pandas
# Note - you may need to `pip install xlrd`
df = pd.read_excel('/Users/bane/Downloads/WFA.xlsx')
coords = df[['X', 'Y', 'Z']].values
# Make the structured surface manually
structured = pv.StructuredGrid()
# Set coordinates
structured.points = coords
# Set the dimensions of the structured grid
structured.dimensions = [143, 135, 1]
# Apply an Elevation filter
elevation = structured.elevation()
elevation.plot(show_edges=True, show_grid=True, notebook=False)
from pyvista-support.
We should add this as an example in the docs.
Looks great @banesullivan!
from pyvista-support.
Hi @gunjan71011! Could you perhaps share a data file with this type of point data set?
Are your points scattered? or do they have some sort of inherit structure?
Perhaps a quick/dirty approach would be to run a Delaunay triangulation much like this example. To say anything more, I'd need to see the dataset either with a data file or if you could take screenshots from plotting the point set with PyVista.
from pyvista-support.
@gunjan71011, did you attach the file to the email when you replied? You may need to visit this thread’s webpage and drag’n’drop the file into the text box
from pyvista-support.
import pandas as pd
import numpy as np
import pyvista as pv
# Load Excel sheet using Pandas
# Note - you may need to `pip install xlrd`
df = pd.read_excel('/Users/bane/Downloads/WFA.xlsx')
coords = df[['X', 'Y', 'Z']].values
# Preview the coordinates to see what we are dealing with
poly = pv.PolyData(coords)
poly['order'] = np.linspace(0,1,poly.n_points)
poly.plot(notebook=False, show_grid=True, point_size=1)
The coordinates definitely have some sort of inherit structure present as I can see a structured grid of the points that is a bit rotated from the cartesian reference frame. This dataset would work well if we know the dimensions of the structured grid (nx by ny by 1) as we could recover that structure and add connectivity with quad cells, but this is incredibly difficult to do without knowing the dimensions of the grid (and assuming the coordinates are ordered which they appear to be from the linear trends in the color mapping shown above). Perhaps the original source of this dataset has more details on the grid's structure?
The quick and dirty method of Delaunay triangulation would work to create a surface, however this is a bit expensive for this dataset as it will have twice as many cells as a structured grid with quads and not have exactly the resolution you might desire:
surf = poly.delaunay_2d()
surf.plot(notebook=False, show_grid=True)
So this new surface mesh has 38056 triangle cells and 19305 points. Ideally, I'd like to see this mesh as a structured grid with quads and not a polygonal surface, so here's an attempt to recover the structure of the gird which I did by brought force guessing dimensions that looked right and were multiples of the total number of points. I ended up with [143, 135, 1]
:
# Make the structured surface manually
structured = pv.StructuredGrid()
# Set coordinates
structured.points = coords
# Set the dimensions of the structured grid
structured.dimensions = [143, 135, 1]
# Apply an Elevation filter
elevation = structured.elevation()
elevation.plot(show_edges=True, show_grid=True, notebook=False)
And there you have it, a properly structured surface from your point set with 19028 quad cells and 19305 points/nodes!
from pyvista-support.
Added a simple example and linked to this issue for a better/more complicated example
from pyvista-support.
Thanks that looks good, although being able to see the changes in elevation would be nice. But thanks for the help!
from pyvista-support.
although being able to see the changes in elevation would be nice
Maybe try adding exaggeration to the render view:
plotter = pv.Plotter(notebook=False)
plotter.add_mesh(elevation)
plotter.set_scale(1, 1, 10)
plotter.show()
from pyvista-support.
Thanks Bane! That really makes the surface stand out. However, I noticed that if there are multiple surfaces in one plotter then all of it would be exaggerted by the same amount (plotter.set_scale(1, 1, 10)). Is there a way to give each mesh its own exaggeration?
from pyvista-support.
However, I noticed that if there are multiple surfaces in one plotter then all of it would be exaggerted by the same amount (plotter.set_scale(1, 1, 10)). Is there a way to give each mesh its own exaggeration?
You could give each dataset it's own exaggeration by editing the coordinates of each mesh individually and leaving the scale alone - the set_scale
function exaggerates the entire render view's spatial reference system so it would be impossible for us to set a scale on each dataset individually and have them still appear next to each other. As a user, though, you could manually scale and shift datasets to your liking. Try editing and shifting the .points
of your different meshes before plotting and not using the set_scale
function:
import pyvista as pv
from pyvista import examples
data = examples.download_bolt_nut()
bolt = data['bolt'].threshold(1)
nut = data['nut'].threshold(1)
# Original data
p = pv.Plotter()
p.add_mesh(bolt)
p.add_mesh(nut)
p.show(use_panel=False)
# Scale and shift the bolt
bolt.points[:,1] *=3
bolt.points[:,1] -= bolt.points[:,1].ptp()/2
#scale and shift the nut
nut.points[:,0] *=3
nut.points[:,0] -= nut.points[:,0].ptp()/2
nut.points[:,2] *=3
nut.points[:,2] -= nut.points[:,2].ptp()/2
p = pv.Plotter()
p.add_mesh(bolt)
p.add_mesh(nut)
p.show(use_panel=False)
from pyvista-support.
Would it be possible to implement either a set_scale on the actor or maybe make it a keyword arg for add_mesh?
from pyvista-support.
That could also work... but you might still need to shift the datasets around to make sure they appear next to each other?
from pyvista-support.
Good point. Maybe a scene-wise implementation is best.
from pyvista-support.
Maybe a scene-wise implementation is best.
That's what I went with by implementing set_scale
a while back. I very often have to exaggerate the Z axis and found that a scene wide scaling worked best - its quite rare (in my experience) to need individual exaggerations per mesh in a single scene
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.