mayavi

Mayavi/mlab: Plot triangles with colour data per triangle, not per vertex

安稳与你 提交于 2019-12-10 21:56:44
问题 If one uses the function triangular_mesh one can pass a set of triangles, given as lists of indices, the vertex positions and a set of data to to assign colours to the vertices. The triangles are then coloured by interpolation between the vertex colours. How can I assign colours triangle-wise, without any interpolation? 回答1: This was asked on the scipy mailing list too. You can't do it with triangular_mesh, but you can if you make a generic surface using a triangular mesh as a source. s =

Mayavi: interpolate face colors in triangular_mesh

邮差的信 提交于 2019-12-10 19:43:53
问题 I have pieced together the following code to plot a triangular mesh with the colors specified by an additional scalar function: #! /usr/bin/env python import numpy as np from mayavi import mlab # Create cone n = 8 t = np.linspace(-np.pi, np.pi, n) z = np.exp(1j*t) x = z.real.copy() y = z.imag.copy() z = np.zeros_like(x) triangles = [(0, i, i+1) for i in range(n)] x = np.r_[0, x] y = np.r_[0, y] z = np.r_[1, z] t = np.r_[0, t] # These are the scalar values for each triangle f = np.mean(t[np

Mayavi, python axes INDICATOR

血红的双手。 提交于 2019-12-10 17:45:12
问题 does anyone know how to switch on the axes INDICATOR in python code? I can switch it on when the graph is plotted, but I wanna know how to do it in code. I have found only how to switch on the axes: mlab.axes() but it is not the indicator (I mean that three arrows X,Y and Z) Thank you 回答1: The following code switches on the axes indicator: mlab.orientation_axes() 来源: https://stackoverflow.com/questions/26034560/mayavi-python-axes-indicator

Can Mayavi render a figure scene with a transparent background?

醉酒当歌 提交于 2019-12-10 13:01:35
问题 I am generating a mesh plot using mayavi.mlab and want the background opacity to be 0. (or transparent). Is this possible? 回答1: If your goal is to integrate the mayavi figure into a matplotlib figure, this is possible. You can use mlab.screenshot to get a numpy array of RGBA values, and mlab will set background pixels to have alpha 0 automatically. You can then add this RGBA matrix to a matlab figure via imshow . Example (adapted from here): import numpy as np from mayavi import mlab import

In Python, how can I export a 3D isosurface into Blender

社会主义新天地 提交于 2019-12-10 07:47:12
问题 I have some 3D (x,y,z,value) data in python and I can visualize the isosurfaces in Mayavi. How can I export this isosurface into a file that I can read into Blender? Here is some example code: import numpy from mayavi import mlab x, y, z = numpy.ogrid[-5:5:64j, -5:5:64j, -5:5:64j] values = x * x * 0.5 + y * y + z * z * 2.0 mlab.contour3d(values, contours=[.5]) mlab.show() 回答1: Using @timday's suggestion, I added the following code to save the isosurface in a wavefront (.obj) format: mlab

locking camera in mayavi

限于喜欢 提交于 2019-12-10 03:05:41
问题 I'm trying to make an animation with a sequence of datafiles in mayavi. Unfortunately i have noticed that camera doesn't lock (it is zooming and zooming out). I think it is happening because the Z componrnt of my mesh is changing and mayavi is trying to recalculate scales. How can I fix it? import numpy from mayavi import mlab mlab.figure(size = (1024,768),bgcolor = (1,1,1)) mlab.view(azimuth=45, elevation=60, distance=0.01, focalpoint=(0,0,0)) #mlab.move(forward=23, right=32, up=12) for i in

Mayavi: rotate around y axis

江枫思渺然 提交于 2019-12-10 02:06:12
问题 I'm plotting a 3D mesh using mayavi's triangular_mesh method. The data describes a human silhouette laying face-down in 3D space (so the cmap can be used to denote distance from the camera). Here's the code used to generate the plot (the faces and vertices come from an external object, and there are far too many to show here): from mayavi import mlab import math import numpy as np import sys import os fig = mlab.figure(fgcolor=(0, 0, 0), bgcolor=(1, 1, 1), size=(1920, 980)) a = np.array(this

Mayavi points3d with different size and colors

℡╲_俬逩灬. 提交于 2019-12-09 02:31:57
问题 Is it possible in mayavi to specify individually both the size and the colors of every point? That API is cumbersome to me. points3d(x, y, z...) points3d(x, y, z, s, ...) points3d(x, y, z, f, ...) x, y and z are numpy arrays, or lists, all of the same shape, giving the positions of the points. If only 3 arrays x, y, z are given, all the points are drawn with the same size and color. In addition, you can pass a fourth array s of the same shape as x, y, and z giving an associated scalar value

Plotting function of 3 dimensions over given domain with matplotlib

為{幸葍}努か 提交于 2019-12-08 04:14:21
问题 I am trying to visualize a function of 3 parameters over a cube in R^3 to get an idea of the smoothness of the function. An example of this problem is shown in the sample code below %pylab from mpl_toolkits.mplot3d import Axes3D import itertools x = np.linspace(0,10,50) y = np.linspace(0,15,50) z = np.linspace(0,8,50) points = [] for element in itertools.product(x, y, z): points.append(element) def f(vals): return np.cos(vals[0]) + np.sin(vals[1]) + vals[2]**0.5 fxyz = map(f, points) xi, yi,

Mayavi Mlab : Drawing octahedrons

一笑奈何 提交于 2019-12-08 03:30:39
问题 I cannot find a way to draw octahedrons. Could someone point me to a class for drawing triangular (transclucent) surfaces at the least? tvtk.tools.visual seems to have only a few basic shapes. 回答1: The Gallery has an example of how to use triangular_mesh: import numpy as np import mayavi.mlab as ML verts = [(1,-1,0), (1,1,0), (-1,1,0), (-1,-1,0), (0,0,1), (0,0,-1)] x, y, z = zip(*verts) # Each triangle is a 3-tuple of indices. The indices are indices of `verts`. triangles = [(i, (i+1)%4, j)