def get_axes(world): axes = Axes( world, xtitle='y: North (m)', # swap axis to plot correctly ytitle='x: East (m)', ztitle='z: TVD (m)', xTitleJustify='bottom-right', yTitleJustify='top-right', zTitleJustify='top-right', xyGrid2=True, xyGrid=False, zxGrid=True, yzGrid2=True, zxGridTransparent=True, yzGrid2Transparent=True, yzGrid=False, xLabelRotation=-1, yLabelRotation=1, zLabelRotation=1, ) for a in axes.unpack(): # unpack the Assembly to access its elements if 'title' in a.name or 'NumericLabel' in a.name: a.mirror('y') if 'yNumericLabel' in a.name: a.scale(0.8) return axes
def onkeypress( self, evt): ###################################### MORPH & GENERATE if evt.keyPressed == 'm': ##--------- morph mesh1 based on the existing arrows if len(self.arrow_starts) != len(self.arrow_stops): printc("You must select your end point first!", c='y') return output = [self.mesh1.clone().c('grey4'), self.mesh2, self.msg2] warped_plane = self.plane1.clone().pickable(False) warped_plane.warp(self.arrow_starts, self.arrow_stops, mode=self.mode) output.append(warped_plane + Axes(warped_plane, xyGrid=0, textScale=0.6)) mw = self.mesh1.clone().applyTransform( warped_plane.transform).c('red4') output.append(mw) T_inv = warped_plane.transform.GetInverse() a = Points(self.arrow_starts, r=10).applyTransform(warped_plane.transform) b = Points(self.arrow_stops, r=10).applyTransform(warped_plane.transform) self.dottedln = Lines( a, b, res=self.n).applyTransform(T_inv).pointSize(5) output.append(self.dottedln) self.msg1.text(self.instructions) self.msg2.text("Morphed output:") self.plotter.clear(at=1).addRendererFrame().add(output, at=1) elif evt.keyPressed == 'g': ##------- generate intermediate shapes if not self.dottedln: return intermediates = [] allpts = self.dottedln.points() allpts = allpts.reshape(len(self.arrow_starts), self.n + 1, 3) for i in range(self.n + 1): pi = allpts[:, i, :] m_nterp = self.mesh1.clone().warp(self.arrow_starts, pi, mode=self.mode).c('b3').lw(1) intermediates.append(m_nterp) self.msg2.text("Morphed output + Interpolation:") self.plotter.add(intermediates, at=1) self.dottedln = None elif evt.keyPressed == 'c': ##------- clear all self.arrow_starts = [] self.arrow_stops = [] self.toggle = False self.dottedln = None self.msg1.text(self.instructions) self.msg2.text("[output will show here]") self.plotter.clear(at=0).clear(at=1).addRendererFrame() self.plotter.add([self.plane1, self.msg1, self.mesh1, self.mesh2], at=0) self.plotter.add([self.plane2, self.msg2], at=1)
def start( self): ################################################ show stuff paxes = Axes(self.plane1, xyGrid=0, textScale=0.6) self.plotter.show(self.plane1, paxes, self.msg1, self.mesh1, self.mesh2, at=0) self.plotter.show(self.plane2, self.msg2, at=1, mode='image') if len(self.arrow_starts): self.draw(True) self.draw(False) self.msg1.text(self.instructions) self.plotter.show(interactive=True, zoom=1.3).close()
"""Customizing Axes. Cartesian planes can be displaced from their lower-range default position""" from vedo import Sphere, Axes, precision, show sph = Sphere().scale([4, 3, 2]).shift(5, 6, 7).c('green2', 0.1) axs = Axes( sph, # build axes for object sph xtitle="x axis", ytitle="y axis", ztitle="z axis", htitle='An ellipsoid at ' + precision(sph.centerOfMass(), 2), hTitleFont=1, hTitleColor='red3', zxGrid=True, xyFrameLine=2, yzFrameLine=2, zxFrameLine=2, xyFrameColor='red3', yzFrameColor='green3', zxFrameColor='blue3', xyShift=0.2, # move xy plane 20% along z yzShift=0.2, # move yz plane 20% along x zxShift=0.2, # move zx plane 20% along y ) show(sph, axs, __doc__)
import numpy as np from vedo import dataurl, Volume, Axes, show from vedo.pyplot import histogram, plot cmap = 'nipy_spectral' alpha = np.array([0, 0, 0.05, 0.2, 0.8, 1]) vol = Volume(dataurl + "embryo.slc") vol.cmap(cmap).alpha(alpha).addScalarBar3D(c='w') xvals = np.linspace(*vol.scalarRange(), len(alpha)) p = histogram(vol, logscale=True, c=cmap, bc='white') p += plot(xvals, alpha * p.ybounds()[1], '--ow').z(1) show( [(vol, Axes(vol, c='w'), f"Original Volume\ncolor map: {cmap}"), (p, "Voxel scalar histogram\nand opacity transfer function")], N=2, sharecam=False, bg=(82, 87, 110), )
sin(state[2]) * cosa + M2 * L2 * state[3] * state[3] * sina - (M1 + M2) * G * sin(state[0])) / den1 dydx[2] = state[3] den2 = (L2 / L1) * den1 dydx[3] = (-M2 * L2 * state[3] * state[3] * sina * cosa + (M1 + M2) * G * sin(state[0]) * cosa - (M1 + M2) * L1 * state[1] * state[1] * sina - (M1 + M2) * G * sin(state[2])) / den2 return dydx t = np.arange(0.0, 10.0, dt) state = np.radians([th1, w1, th2, w2]) y = integrate.odeint(derivs, state, t) P1 = np.dstack([L1 * sin(y[:, 0]), -L1 * cos(y[:, 0])]).squeeze() P2 = P1 + np.dstack([L2 * sin(y[:, 2]), -L2 * cos(y[:, 2])]).squeeze() ax = Axes(xrange=(-2, 2), yrange=(-2, 1), htitle=__doc__) pb = ProgressBar(0, len(t), c="b") for i in pb.range(): j = max(i - 5, 0) k = max(i - 10, 0) l1 = Line([[0, 0], P1[i], P2[i]]).lw(7).c("blue2") l2 = Line([[0, 0], P1[j], P2[j]]).lw(6).c("blue2", 0.3) l3 = Line([[0, 0], P1[k], P2[k]]).lw(5).c("blue2", 0.1) pt = Points([P1[i], P2[i], P1[j], P2[j], P1[k], P2[k]], r=8).c("blue2", 0.2) show(l1, l2, l3, pt, ax, interactive=False, size=(900, 700), zoom=1.4) pb.print()
ws.append(w) # print(i, 'whisker:\n', w.info) # build some theoretical expectation to be shown as a grey band x = np.linspace(-1, 9, 100) y = x / 5 + 0.2 * np.sin(x) ye = y**2 / 5 + 0.1 # error on y line = Line(np.c_[x, y]) band = Ribbon(np.c_[x, y - ye], np.c_[x, y + ye]).c('black', 0.1) # build braces to inndicate stats significance and dosage bra1 = Brace([0, 3], [2, 3], comment='*~*', s=0.7, style='[') bra2 = Brace([4, -1], [8, -1], comment='dose > 3~\mug/kg', s=0.7) # build custom axes axes = Axes( xrange=[-1, 9], yrange=[-3, 5], htitle='\beta_c -expression: change in time', xtitle=' ', ytitle='Level of \beta_c protein in \muM/l', xValuesAndLabels=[ (0, 'Experiment^A\nat t=1h'), (4, 'Experiment^B\nat t=2h'), (8, 'Experiment^C\nat t=4h'), ], xLabelSize=0.02, ) show(ws, bra1, bra2, line, band, __doc__, axes, zoom=1.1)