def showSolution3D(S, start, goal): from vedo import Text3D, Cube, Line, Grid, merge, show pts, cubes, txts = [], [], [] pts = [(x, -y) for y, x in S[0]] for y, line in enumerate(Z): for x, c in enumerate(line): if c: cubes.append(Cube([x, -y, 0])) path = Line(pts).lw(6).c('tomato') walls = merge(cubes).clean().flat().texture('wood1') sy, sx = S[1].shape gradient = np.flip(S[1], axis=0).ravel() grd = Grid(pos=((sx - 1) / 2, -(sy - 1) / 2, -0.49), sx=sx, sy=sy, resx=sx, resy=sy) grd.lw(0).wireframe(False).cmap('gist_earth_r', gradient, on='cells') grd.addScalarBar(title='Gradient', horizontal=True, c='k', nlabels=2) txts.append(__doc__) txts.append(Text3D('Start', pos=[start[1] - 1, -start[0] + 1.5, 1], c='k')) txts.append(Text3D('Goal!', pos=[goal[1] - 2, -goal[0] - 2.7, 1], c='k')) show(path, walls, grd, txts, axes=0, zoom=1.2)
counts = [1946, 8993, 3042, 1190, 1477, 0, 0] percent = [11.68909178, 54.01850072, 18.27246516, 7.14800577, 8.87193657, 0, 0] labels = [ '<100', '100-250', '250-500', '500-750', '750-1000', '1000-2000', '>2000' ] colors = colorMap(range(len(counts)), "hot") plt = plot( [counts, labels, colors], mode="bars", ylim=(0, 10500), aspect=4 / 3, axes=dict( htitle="Clusters in lux range", hTitleItalic=False, xLabelRotation=35, xLabelSize=0.02, tipSize=0, # axes arrow tip size ), ) for i in range(len(percent)): val = precision(percent[i], 3) + '%' txt = Text3D(val, pos=(plt.centers[i], counts[i]), justify="bottom-center", c="blue2") plt += txt.scale(200).shift(0, 150, 0) plt.show(size=(1000, 750), zoom=1.3, viewup='2d').close()
) plt += DashedLine(x, y) # Fit points and evaluate, with a boostrap and Monte-Carlo technique, # the correct errors and error bands. Return a Line object: pfit = fit([x, y+noise], deg=deg, # degree of the polynomial niter=500, # nr. of MC iterations to compute error bands nstd=2, # nr. of std deviations to display xerrors=xerrs, # optional array of errors on x yerrors=yerrs, # optional array of errors on y vrange=(-3,15), # specify the domain of fit ) plt += [pfit, pfit.errorBand, *pfit.errorLines] # add these objects to Plot txt = "fit coefficients:\n " + precision(pfit.coefficients, 2) \ + "\n\pm" + precision(pfit.coefficientErrors, 2) \ + "\n\Chi^2_\nu = " + precision(pfit.reducedChi2, 3) plt += Text3D(txt, s=0.42, font='VictorMono').pos(2,-2).c('k') # Create an histo to show the correlation of fit parameters h = histogram(pfit.MonteCarloCoefficients[:,0], pfit.MonteCarloCoefficients[:,1], title="parameters correlation", xtitle='coeff_0', ytitle='coeff_1', cmap='bone_r', scalarbar=True) h.scale(150).shift(-1,11) # make it a lot bigger and move it show(plt, h, zoom=1.3, mode="image").close()
from vedo import Volume, Text3D, show, dataurl vol = Volume(dataurl+"embryo.slc").mode(0).c('b2').alphaUnit(5) t = Text3D("Sharpe\n~~~Lab", s=40, font="Spears", vspacing=1.4, depth=.04) t.c('k1').rotateX(90).pos(200,150,70) cam = dict(pos=(363, -247, 121), focalPoint=(240, 137, 116), viewup=(4.45e-3, 0.0135, 1.00), distance=403) show(vol, t, size=(700,400), camera=cam)
\intx\dot~dx = \onehalf x\^2 + const. d^2 x^\mu + \Gamma^\mu_\alpha\beta ~dx^\alpha ~dx^\beta = 0 -∇\^2u(x) = f(x) in Ω, u(x)~=~u_D (x) in \partial\Omega Protect underscore \\\_ and \\\^ with a backslash. """ plt = Plotter(N=4, pos=(300, 0), size=(1600, 950)) cam = dict(pos=(3.99e+5, 8.51e+3, 6.47e+5), focalPoint=(2.46e+5, 1.16e+5, -9.24e+3), viewup=(-0.0591, 0.983, 0.175), distance=6.82e+5, clippingRange=(5.26e+5, 8.92e+5)) for i, fnt in enumerate(["Kanopus", "Normografo", "Theemim", "VictorMono"]): t = Text3D(txt, font=fnt, italic=0).c('darkblue').scale(12300) plt.show( t, Text2D("Font: " + fnt, font=fnt, bg='r'), axes=dict( xtitle='my units for L_x (\mum)', ytitle='my Y-axis with\na long description', titleFont=fnt, labelFont=fnt, digits=2, ), at=i, camera=cam, resetcam=not bool(i), )
def make_actor_label( atlas, actors, labels, size=300, color=None, radius=100, xoffset=0, yoffset=-500, zoffset=0, ): """ Adds a 2D text ancored to a point on the actor's mesh to label what the actor is :param kwargs: key word arguments can be passed to determine text appearance and location: - size: int, text size. Default 300 - color: str, text color. A list of colors can be passed if None the actor's color is used. Default None. - xoffset, yoffset, zoffset: integers that shift the label position - radius: radius of sphere used to denote label anchor. Set to 0 or None to hide. """ offset = [-yoffset, -zoffset, xoffset] default_offset = np.array([0, -200, 100]) new_actors = [] for n, (actor, label) in enumerate(zip(listify(actors), listify(labels))): # Get label color if color is None: color = [0.2, 0.2, 0.2] # Get mesh's highest point points = actor.points().copy() point = points[np.argmin(points[:, 1]), :] point += np.array(offset) + default_offset try: if atlas.hemisphere_from_coords(point, as_string=True) == "left": point = atlas.mirror_point_across_hemispheres(point) except IndexError: pass # Create label txt = Text3D(label, point, s=size, c=color) txt._kwargs = dict( size=size, color=color, radius=radius, xoffset=xoffset, yoffset=yoffset, zoffset=zoffset, ) # rotate label p = txt.pos() txt.pos(x=0, y=0, z=0).rotateX(180).rotateY(180).pos(p) new_actors.append(txt) # Mark a point on Mesh that corresponds to the label location if radius is not None: pt = actor.closestPoint(point) sphere = Sphere(pt, r=radius, c=color) sphere.ancor = pt new_actors.append(sphere) return new_actors
"""Embed a 3D scene in a webpage with x3d""" from vedo import dataurl, Plotter, Volume, Text3D plt = Plotter(size=(800, 600), bg='GhostWhite') embryo = Volume(dataurl + 'embryo.tif').isosurface().decimate(0.5) coords = embryo.points() embryo.cmap('PRGn', coords[:, 1]) # add dummy colors along y txt = Text3D(__doc__, font='Bongas', s=350, c='red2', depth=0.05) txt.pos(2500, 300, 500) plt.show(embryo, txt, txt.box(pad=250), axes=1, viewup='z', zoom=1.2) # This exports the scene and generates 2 files: # embryo.x3d and an example embryo.html to inspect in the browser plt.export('embryo.x3d', binary=False) print("Type: \n firefox embryo.html")
"""Markers set, analogous to matplotlib""" from vedo import Plotter, Marker, Text3D symbols = [ '.', 'p', '*', 'h', 'D', 'd', 'o', 'v', '>', '<', 's', 'x', '+', 'a' ] plt = Plotter(size=(1500, 300), axes=0) for i, s in enumerate(symbols): plt += Marker(s, filled=True).x(i * 0.6).color(i) plt += Text3D(s, pos=[i * 0.6, -0.6, 0], s=0.12).color('k') plt += __doc__ plt.show(zoom=5, viewup='2d').close()