Skip to content

Commit

Permalink
4.1 scalarbars
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Oct 6, 2020
1 parent c2cb3a4 commit 1447aab
Show file tree
Hide file tree
Showing 28 changed files with 434 additions and 444 deletions.
6 changes: 3 additions & 3 deletions examples/basic/flatarrow.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Use 2 lines to define a flat arrow"""
from vedo import *

arrs = []
for i in range(10):
s, c = sin(i), cos(i)
l1 = [[sin(x)+c, -cos(x)+s, x] for x in arange(0,3, 0.1)]
l2 = [[sin(x)+c+0.1, -cos(x)+s + x/15, x] for x in arange(0,3, 0.1)]

FlatArrow(l1, l2, c=i, tipSize=1, tipWidth=1)
arrs.append(FlatArrow(l1, l2, c=i, tipSize=1, tipWidth=1))

# three points, aka ellipsis, retrieves the list of all created actors
show(..., __doc__, viewup="z", axes=1)
show(arrs, __doc__, viewup="z", axes=1)
5 changes: 3 additions & 2 deletions examples/basic/linInterpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

# now use linInterpolate to interpolate linearly any other point in space
# (points far from both positions will get close to the directions average)
arrs = []
for x in range(0,10):
for y in range(0,10):
p = [x/5, y/5, 0]
v = linInterpolate(p, positions, directions)
Arrow(p, p+v, s=0.001)
arrs.append(Arrow(p, p+v, s=0.001))

show(..., __doc__, axes=1)
show(arrs, __doc__, axes=1)
2 changes: 1 addition & 1 deletion examples/basic/mesh_coloring.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
man2 = load(datadir+"man_low.vtk")
scals = man2.points()[:, 0] + 37 # pick x coordinates of vertices

man2.cmap("hot", scals, vmax=37)
man2.cmap("hot", scals)
man2.addScalarBar(horizontal=True)
show(man2, "mesh.cmap()", at=1)

Expand Down
48 changes: 32 additions & 16 deletions examples/basic/mesh_lut.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
from vedo import makeLUT, Sphere
"""Build a custom colormap, including
out-of-range and NaN colors and labels"""
from vedo import buildLUT, Sphere, show, settings

mesh = Sphere().lineWidth(0.1)
# settings.useDepthPeeling = True # might help with transparencies

# create some data array to be associated to points
data = mesh.points()[:,2]
data[10:20] = float('nan')
# generate a sphere and stretch it, so it sits between z=-2 and z=+2
mesh = Sphere(quads=True).scale([1,1,2]).lineWidth(0.1)

# Build a lookup table of colors:
# scalar color alpha
lut = makeLUT( [(-0.80, 'pink' ),
(-0.33, 'green', 0.8),
( 0.67, 'red' ),
# create some dummy data array to be associated to points
data = mesh.points()[:,2] # pick z-coords, use them as scalar data
data[10:70] = float('nan') # make some values invalid by setting to NaN
data[300:600] = 100 # send some values very far above-scale

# build a custom LookUp Table of colors:
# value, color, alpha
lut = buildLUT([
#(-2, 'pink' ), # up to -2 is pink
(0.0, 'pink' ), # up to 0 is pink
(0.4, 'green', 0.5), # up to 0.4 is green with alpha=0.5
(0.7, 'darkblue' ),
#( 2, 'darkblue' ),
],
vmin=-1, vmax=1,
aboveColor='grey',
belowColor='white',
vmin=-1.2, belowColor='lightblue',
vmax= 0.7, aboveColor='grey',
nanColor='red',
interpolate=False,
)
)
# 3D scalarbar:
mesh.cmap(lut, data).addScalarBar3D(title='My 3D scalarbar', c='white')
mesh.scalarbar.scale(1.5).rotateX(90).y(1) # make it bigger and place it

mesh.cmap(lut, data).addScalarBar()
# 2D scalarbar:
# mesh.cmap(lut, data).addScalarBar()

mesh.show(axes=1, viewup='z')
show(mesh, __doc__,
axes=dict(zLabelSize=.04, numberOfDivisions=10),
elevation=-80, bg='blackboard',
)
35 changes: 17 additions & 18 deletions examples/basic/mesh_merge_vs_assembly.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
'''
Mesh objects can be combined with
(1) `mesh.merge` - creates a new mesh object; this new mesh inherits properties (color, etc.) of the first mesh.
(2) `assembly.Assembly` - combines meshes (or other actors); preserves properties
(2) `assembly.Assembly` - groups meshes (or other actors); preserves properties
(3) `+` - equivalent to `Assembly`
'''

# credits: https://github.com/icemtel
import vedo
import numpy as np

# Define vertices and faces
verts = np.array([(0, 0, 0), (10, 0, 0), (0, 10, 0), (0, 0, 10)])
faces = np.array([(0, 1, 2), (2, 1, 3), (1, 0, 3), (0, 2, 3)])
verts = [(0, 0, 0), (10, 0, 0), (0, 10, 0), (0, 0, 10)]
faces = [(0, 1, 2), (2, 1, 3), (1, 0, 3), (0, 2, 3)]
# Create a tetrahedron and a copy
mesh = vedo.Mesh([verts, faces], c='red')
mesh2 = mesh.clone().x(15).y(15).c('blue') # Create a copy, shift it; change color
mesh1 = vedo.Mesh([verts, faces], c='red')
mesh2 = mesh1.clone().pos(15,15,0).c('blue') # Create a copy, position it; change color

# Merge: creates a new mesh, color of the second mesh is lost
mesh_all = vedo.merge(mesh, mesh2)
# Merge: creates a new mesh, fusion of the 2 inputs. Color of the second mesh is lost.
mesh_all = vedo.merge(mesh1, mesh2)
print('1. Type:', type(mesh_all))
# Show
plotter = vedo.show(mesh_all, viewup='z', axes=1) # -> all red
plotter = vedo.show("mesh.merge(mesh1, mesh2) creates a single new Mesh object",
mesh_all, viewup='z', axes=1) # -> all red
plotter.close()

# Assembly: groups meshes
mesh_all = vedo.assembly.Assembly(mesh, mesh2)
# Assembly: groups meshes. Objects keep their individuality (can be later unpacked).
mesh_all = vedo.Assembly(mesh1, mesh2)
print('2. Type:', type(mesh_all))
# Show
plotter = vedo.show(mesh_all, viewup='z', axes=1) # -> red and blue
plotter = vedo.show("Assembly(mesh1, mesh2) groups meshes preserving their properties",
mesh_all, viewup='z', axes=1) # -> red and blue
plotter.close()

# Equivalently, "+" also creates an Assembly
mesh_all = mesh + mesh2
mesh_all = mesh1 + mesh2
print('3. Type:', type(mesh_all))
# Show
plotter = vedo.show(mesh_all, viewup='z', axes=1) # -> red and blue
plotter = vedo.show("mesh1+mesh2 operator is equivalent to Assembly()",
mesh_all, viewup='z', axes=1) # -> red and blue
plotter.close()
7 changes: 0 additions & 7 deletions examples/basic/multiblock.vtm

This file was deleted.

37 changes: 0 additions & 37 deletions examples/basic/multiblock/multiblock_0.vtp

This file was deleted.

16 changes: 0 additions & 16 deletions examples/basic/multiblock/multiblock_1.vti

This file was deleted.

14 changes: 0 additions & 14 deletions examples/basic/noname.py

This file was deleted.

9 changes: 4 additions & 5 deletions examples/other/makeVideo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
vp.load(datadir+"spider.ply").texture("leather").rotateX(-90)

# open a video file and force it to last 3 seconds in total
video = Video("spider.mp4", duration=6, backend='opencv') # backend='opencv'
video = Video("spider.mp4", duration=6, backend='ffmpeg') # backend='opencv'

# Any rendering loop goes here, e.g.:
#for i in range(80):
# vp.show(elevation=1, azimuth=2) # render the scene
# video.addFrame() # add individual frame
# for i in range(80):
# vp.show(elevation=1, azimuth=2) # render the scene
# video.addFrame() # add individual frame

# OR use the automatic video shooting function:

video.action(zoom=1.1)
#Options are: elevation_range=(0,80),
# azimuth_range=(0,359),
Expand Down
18 changes: 10 additions & 8 deletions examples/pyplot/fonts3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@


################################################################################## 2D
acts2d = []
for i, f in enumerate(fonts):
Text2D(f+': The quick fox jumps over the lazy dog. 1234567890 αβγδεθλμνπστφψω',
pos=(.015, 1-(i+3)*.06), font=f, s=1.3, c='k')
t = Text2D(f+': The quick fox jumps over the lazy dog. 1234567890 αβγδεθλμνπστφψω',
pos=(.015, 1-(i+3)*.06), font=f, s=1.3, c='k')
acts2d.append(t)

Text2D("List of Available Fonts", pos='top-center', bg='k', s=1.1)
show(..., bg2='cornsilk', axes=False, zoom=1.2, size=(1200,700), interactive=False)
acts2d.append(Text2D("List of Available Fonts", pos='top-center', bg='k', s=1.1))
show(acts2d, bg2='cornsilk', axes=False, zoom=1.2, size=(1200,700), interactive=False)


################################################################################## 3D
Expand Down Expand Up @@ -75,11 +77,11 @@
printc('Font: ', f, c='g')

################################################################################## 3D
cam = dict(pos=(59.7, -2.91, 122),
focalPoint=(27.2, -31.2, 0.890),
cam = dict(pos=(55.8, -4.27, 107),
focalPoint=(27.1, -29.2, -0.0532),
viewup=(-0.0642, 0.976, -0.210),
distance=129,
clippingRange=(101, 167))
distance=113,
clippingRange=(87.1, 147))

ln1 = Line([-1,-2],[52,-2], lw=0.1, c='grey')
fn3d=[ln1]
Expand Down
22 changes: 9 additions & 13 deletions examples/pyplot/histo_violin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@

n = 1000

acts = [
Text('gaussian', pos=(0,4.5), s=0.3, c='k', justify='center'),
violin(np.random.randn(n)),

Text('gaussian', pos=(0,4.5), s=0.3, c='k', justify='center')
violin(np.random.randn(n))
Text('exponential', pos=(5,-1), s=0.3, c='k', justify='center'),
violin(np.random.exponential(1, n), x=5, width=3, spline=False, centerline=False, c='t', lc='k'),

Text('chisquare', pos=(10,11), s=0.3, c='k', justify='center'),
violin(np.random.chisquare(9, n)/4, x=10, vlim=(0,10), c='lg', lc='dg'),
]

Text('exponential', pos=(5,-1), s=0.3, c='k', justify='center')
violin(np.random.exponential(1, n),
x=5, width=3, spline=False, centerline=False, c='t', lc='k')


Text('chisquare', pos=(10,11), s=0.3, c='k', justify='center')
violin(np.random.chisquare(9, n)/4,
x=10, vlim=(0,10), c='lg', lc='dg')


show(..., axes=dict(xtitle=False, ytitle='distribution'))
show(acts, axes=dict(xtitle=False, ytitle='distribution'))
6 changes: 2 additions & 4 deletions examples/pyplot/plot4_fxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
############################################################### REAL
# an existing function z(x,y) can be passed:
def my_z(x, y): return sin(2*x*y) * cos(3*y)/2
f1 = plot(my_z, c='lb', bc='t')
# f1 = plot(my_z, texture=None, bc=None)
# f1.unpack(0).addElevationScalars().cmap('terrain')
# f1.show()
f1 = plot(my_z, c='summer') # use a colormap
# f1 = plot(my_z, c='lightblue', bc='tomato')

# red dots are shown where the function does not exist (y>x):
f2 = plot("sin(3*x)*log(x-y)/3")
Expand Down
4 changes: 2 additions & 2 deletions examples/pyplot/scatter3.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
pts3 = Glyph([x,y], mark, c='k').z(0.2)


label = Text("preliminary\nresults!", font='Inversionz', s=.8, pos=(-8,4,.2))
label.c('green').rotateZ(20)
label = Text("preliminary\nresults!", font='Quikhand', s=1.5, pos=(-8,4,.2))
label.c('black').rotateZ(20)

show(pts1, pts2, pts3, label, __doc__,
title='A simple scatter plot', axes=1, viewup='2d')
35 changes: 20 additions & 15 deletions examples/simulations/volterra.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,29 @@ def rhs(y0, t, a):
########################################################################
from vedo import *

Arrows(origins, origins+vectors, c='lr')
plt = Plotter(bg="blackboard")
plt += Arrows(origins, origins+vectors, c='lr')

Points(curve_points1, c='y')
Line(curve_points1, c='y')
Line(np.vstack([T, sol1[:,0], sol1[:,1]]).T, c='y')
plt += Points(curve_points1, c='y')
plt += Line(curve_points1, c='y')
plt += Line(np.vstack([T, sol1[:,0], sol1[:,1]]).T, c='y')

Points(curve_points2, c='g')
Line(curve_points2, c='g')
Line(np.vstack([T, sol2[:,0], sol2[:,1]]).T, c='g')
plt += Points(curve_points2, c='g')
plt += Line(curve_points2, c='g')
plt += Line(np.vstack([T, sol2[:,0], sol2[:,1]]).T, c='g')

Points(curve_points3, c='lb')
Line(curve_points3, c='lb')
Line(np.vstack([T, sol3[:,0], sol3[:,1]]).T, c='lb')
plt += Points(curve_points3, c='lb')
plt += Line(curve_points3, c='lb')
plt += Line(np.vstack([T, sol3[:,0], sol3[:,1]]).T, c='lb')

Latex(r'\dot{x}=x-x y', c='white').rotateZ(-90).pos(4,6.5,0)
Latex(r'\dot{y}=\alpha(xy-y)', c='white').rotateZ(-90).pos(3,6.5,0)
plt += Latex(r'\dot{x}=x-x y', c='white').rotateZ(-90).pos(4,6.5,0)
plt += Latex(r'\dot{y}=\alpha(xy-y)', c='white').rotateZ(-90).pos(3,6.5,0)

show(..., __doc__, # all sofar created objects and the header
axes={'xtitle':'time', 'ytitle':'x', 'ztitle':'y', 'zxGrid':True, 'yzGrid':False},
bg="blackboard", viewup='x',
plt += __doc__

plt.show(axes={'xtitle':'time',
'ytitle':'x',
'ztitle':'y',
'zxGrid':True, 'yzGrid':False},
viewup='x',
)
Loading

0 comments on commit 1447aab

Please sign in to comment.