Beispiel #1
0
    def startup( self ) :
        # super().startup()

        # this will reduce the amount of data to roughly a grid of 15x15x15 vectors. can
        # always change later in the gui.
        self.mask_points = int( ( self.data[0].shape[0] / 15. ) ** 3 ) 
        
        for i in range(3) :
            if self.slices_to_add[i] :
                self.add_slice( i )
        
        self.set_orientation_axes( 1 )
        self.set_outline( 1 )
        mlab.vectorbar( orientation = 'vertical' )
        mlab.vectorbar( orientation = 'vertical' )
        # mlab.vectorbar()
        self.needs_startup =  0 
Beispiel #2
0
def vectorbar(*args, **kwargs):
    """Wraps mayavi.mlab.vectorbar and adjusts cmap if you so choose"""
    cmap = kwargs.pop("cmap", False)
    kwargs, cmap_kwargs = _extract_cmap_kwargs(kwargs)
    cmap_kwargs.pop("cmap")
    ret = mlab.vectorbar(*args, **kwargs)
    apply_cmap(ret, cmap=cmap, **cmap_kwargs)
    return ret
Beispiel #3
0
def mayavi_barchart():
    """
    绘制barchart图
    :return:
    """
    mlab.figure(fgcolor=(0, 0, 0), bgcolor=(1, 1, 1))  # 更改背景色
    # s = np.random.rand(3, 3)
    # print(s)
    # mlab.barchart(s)
    # mlab.vectorbar()
    # mlab.show()

    x, y = np.mgrid[-5:5:20j, -5:5:20j]
    # print(x, y)
    s = peaks(x, y)
    mlab.barchart(x, y, s)
    mlab.vectorbar()
    mlab.show()
Beispiel #4
0
    def startup(self):
        # super().startup()

        # print( len( self.data ) )
        src = mlab.pipeline.vector_field(*self.data, figure=self.mayavi_scene)
        self.mayavi_plot = mlab.pipeline.vectors(src, figure=self.mayavi_scene)

        mlab.vectorbar(self.mayavi_plot, orientation='vertical')
        mlab.vectorbar(self.mayavi_plot, orientation='vertical')

        # see https://docs.enthought.com/mayavi/mayavi/auto/example_magnetic_field.html
        self.mayavi_plot.glyph.trait_set(mask_input_points=True)
        self.mayavi_plot.glyph.mask_points.trait_set(on_ratio=2,
                                                     random_mode=False)

        # print_info( self.mayavi_plot.glyph.mask_points )

        self.set_mask_points(5)

        self.set_orientation_axes(1)
        self.set_outline(1)
        self.needs_startup = 0
Beispiel #5
0
data.shape = shape

nx = shape[0]
ny = shape[1]
nz = shape[2]

dx = nx / 2 + 1
dy = ny / 2 + 1
dz = nz / 2 + 1

if hslice:
    amp = np.sqrt(data[:, :, dz, 0]**2 + data[:, :, dz, 1]**2 +
                  data[:, :, dz, 2]**2)
    mlab.imshow(amp, opacity=0.6, reset_zoom=False)

mlab.quiver3d(data[:, :, :, 0],
              data[:, :, :, 1],
              data[:, :, :, 2],
              mask_points=mask_points,
              scale_factor=scale_factor,
              extent=[-dx, dx, -dy, dy, -dz, dz])

if axes:
    mlab.axes()

if colorbar:
    mlab.vectorbar()

mlab.show()
forceY = []
forceZ = []

originX = []
originY = []
originZ = []

i = 0
with open("forceOnObject.txt", "r") as f:
    for line in f:
        vect = line.split('[')[1].split(']')[0].split(',')  # Parse list

        forceX.append(float(vect[0]))
        forceY.append(float(vect[1]))
        forceZ.append(float(vect[2]))

        originX.append(0.0)
        originY.append(time[i])
        originZ.append(0.0)

        i += 1

m.quiver3d(originX, originY, originZ, forceX, forceY, forceZ)

# m.title('Force applied on the house over time')
m.vectorbar(orientation='vertical')
m.ylabel('time (s)')
m.axes()

m.show()
               delimiter='\t',
               newline='\n',
               fmt='%s')

    xx = np.arange(0, len(ef[0]), 1)
    y = np.arange(0, len(ef[0]), 1)
    z = np.arange(0, len(ef[0]), 1)
    Xe, Ye, Ze = np.meshgrid(xx, y, z, indexing='ij')

    norm = o.dimension**3
    print(norm)
    ef = ef / norm
    m.figure()
    m.quiver3d(Xe, Ye, Ze, ef[0], ef[1], ef[2], colormap='gnuplot')
    m.title('E-field/potential - vector/scalar')
    m.vectorbar()
    m.axes(ranges=[0, n, 0, n, 0, n])

    m.figure()
    a = m.contour3d(X, Y, Z, o.potential / norm)
    m.scalarbar()
    m.axes(ranges=[0, n, 0, n, 0, n])
    m.show()

    d_values = []
    p_values = []
    half = int(n / 2)
    for i in range(n):
        for j in range(n):
            for k in range(n):
                distance = np.sqrt(((i - half)**2) + ((j - half)**2) +
Beispiel #8
0
####################################################################################### 
# Calculating the magnetic field of a Current around Loop
#######################################################################################
elif prompt == "L":   
    "Endpoints of vector to rotate circle around"
    x0, y0, z0, x1, y1, z1 = 0, 0, 0, 0, 0, 1
    "Calculate field and graph the wire"
    B_loop(n, x0, y0, z0, x1, y1, z1, 0, 10, 0)
    "Scale and plot the vectors up so they can be seen graphically "
    draw_vector(x_grid, y_grid, z_grid, Bx, By, Bz)

"Current around Solenoid"

#######################################################################################
"""Draw the x, y, z axes"""
axes = np.linspace(-20, 20, 100)
x_axis = mlab.plot3d(0*axes, 0*axes, axes, color=(0,0,0), tube_radius = .02)
y_axis = mlab.plot3d(axes, 0*axes, 0*axes, color=(0,0,0), tube_radius = .02)
z_axis = mlab.plot3d(0*axes, axes, 0*axes, color=(0,0,0), tube_radius = .02)

"Figure Functions"
mlab.title("Magnetic Field", height = .9, size = .45)
mlab.view(distance = 200)

"Vectorbar functions"
vb = mlab.vectorbar(title = "Field Strength (T)", nb_labels = 5)
vb.scalar_bar_representation.position = [0.006644735064188584, 0.016157157980456187]
vb.scalar_bar_representation.position2 = [0.5567139298716236, 0.11830171009771967]
mlab.show()
Beispiel #9
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import mayavi.mlab as mlab

mlab.figure(fgcolor=(0, 0, 0), bgcolor=(1, 1, 1))  #更改背景色
s = np.random.normal(size=(21, 21))
#mlab.barchart(s)        #x,y为矩阵p的坐标,可以省略
#mlab.imshow(s)           # the colormap
x, y = np.mgrid[-10:10:21j, -10:10:21j]
mlab.mesh(x, y, s)
mlab.vectorbar()  #颜色bar
mlab.show()
Beispiel #10
0
from file_reading import read_file
from mayavi import mlab
import matplotlib.pyplot as plt
import numpy as np
import hexbin

t,x,y,z,u,vx,vy,vz,uvx,uvy,uvz = read_file("../Data/h_med_5")

mlab.quiver3d(x,y,z, vx, vy, vz)
mlab.vectorbar(title="Velocity (metres per second)", orientation='Vertical', nb_labels=4)
mlab.show()