Comments (3)
So this issue has to do with the ordering of your scalars and how you want them on your structured grid. Simply raveling the scalars in an 'F'
order resolves this issue. The color mapping and plotting are all doing what they're supposed to, just where the scalars lie on the mesh is incorrect.
The reason the second example works and shows the correct values at their expected locations on the mesh is that those values are totally symmetric - thus the array, when raveled in the C direction (NumPy's default), would have the same values as the F ordered array.
It's important to note that when you pass the array as the scalars
argument in the add_mesh
function, .ravel()
is called internally on that array - you need to ravel it beforehand since it is F-ordered.
To create the correct visualization, ravel the data array so that it makes a flat vector in F order and associate it with the mesh before plotting.
grid = pv.StructuredGrid(x, y, z)
# Add scalars to the mesh and ravel with F order
grid['scalars'] = z.ravel(order='f')
plotter = pv.Plotter()
plotter.add_mesh(grid, scalars='scalars', cmap='viridis', lighting=False)
plotter.add_axes()
plotter.set_scale(xscale=(np.max(z)/np.max(x)),
yscale=(np.max(z)/np.max(y)))
plotter.show_bounds(grid='back',
location='outer',
ticks='both',
bounds=[np.min(x), np.max(x),
np.min(y), np.max(y),
np.min(z), np.max(z)])
plotter.show()
And to prove the symmetry of the second example:
x_samp = np.linspace(-10, 10, 20)
y_samp = np.linspace(-10, 10, 20)
x, y = np.meshgrid(x_samp, y_samp)
a = -0.0001
z = a*(np.abs(np.sin(x)*np.sin(y)*np.exp(np.abs(100-np.sqrt(x**2 + y**2)/np.pi))) + 1)**0.1
assert np.allclose(z.ravel(order='F'), z.ravel(order='c'))
Some additional tips
- avoid using the
add_scalar_bar
method on the plotter - this is meant more for internal use. Theadd_mesh
call can control the scalar bar better if the scalars are associated with the mesh like I do in the snippet above - Be sure to associate scalars with the mesh before plotting - this helps managing those arrays and makes editing the scalar bar and other view properties a bit easier. It's good practice to explicitly use the
.point_arrays
or.cell_arrays
depending on where you want the values to lie.
from pyvista-support.
indeed that solves everything, and with the explicit asignacion of grid['scalars'], add_scalar_bar is not needed anymore.
Thanks
from pyvista-support.
explicit asignacion of grid['scalars'], add_scalar_bar is not needed anymore.
Correct, or if you passed the array as the scalars
argument to the add_mesh
call with a stitle
name, then the scalar bar would appear:
plotter.add_mesh(grid, scalars=z.ravel(order='f'), stitle='My Scalars', cmap='viridis', lighting=False)
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.