Z = np.zeros((n+2, n+2), [('U', np.double), ('V', np.double)]) U, V = Z['U'], Z['V'] u, v = U[1:-1, 1:-1], V[1:-1, 1:-1] r = 20 u[...] = 1.0 U[n//2-r:n//2+r, n//2-r:n//2+r] = 0.50 V[n//2-r:n//2+r, n//2-r:n//2+r] = 0.25 u += 0.05*np.random.uniform(-1, 1, (n, n)) v += 0.05*np.random.uniform(-1, 1, (n, n)) sy, sx = V.shape grd = Grid(sx=sx, sy=sy, resx=sx, resy=sy) grd.lineWidth(0).wireframe(False).lighting(ambient=0.5) formula = r'(u,v)=(D_u\cdot\Delta u -u v v+F(1-u), D_v\cdot\Delta v +u v v -(F+k)v)' ltx = Latex(formula, s=15, pos=(0,-sy/1.9,0)) print('Du, Dv, F, k, name =', Du, Dv, F, k, name) settings.useDepthPeeling = False for step in range(Nsteps): for i in range(25): Lu = ( U[0:-2, 1:-1] + U[1:-1, 0:-2] - 4*U[1:-1, 1:-1] + U[1:-1, 2:] + U[2: , 1:-1]) Lv = ( V[0:-2, 1:-1] + V[1:-1, 0:-2] - 4*V[1:-1, 1:-1] + V[1:-1, 2:] + V[2: , 1:-1]) uvv = u*v*v u += Du*Lu - uvv + F*(1-u) v += Dv*Lv + uvv - (F+k)*v
v = TestFunction(V) a = dot(grad(w), grad(v)) * dx L = p * v * dx # Compute solution w = Function(V) solve(a == L, w, bc) p = interpolate(p, V) # Curve plot along x = 0 comparing p and w import numpy as np tol = 0.001 # avoid hitting points outside the domain y = np.linspace(-1 + tol, 1 - tol, 101) points = [(0, y_) for y_ in y] # 2D points w_line = np.array([w(point) for point in points]) p_line = np.array([p(point) for point in points]) ####################################################################### from vedo.dolfin import plot from vedo import Line, Latex pde = r'-T \nabla^{2} D=p, ~\Omega=\left\{(x, y) | x^{2}+y^{2} \leq R\right\}' tex = Latex(pde, pos=(0, 1.1, .1), s=0.2, c='w') wline = Line(y, w_line * 10, c='white', lw=4) pline = Line(y, p_line / 4, c='lightgreen', lw=4) plot(w, wline, tex, at=0, N=2, bg='bb', text='Deflection') plot(p, pline, at=1, bg='bb', text='Load')
from vedo import Latex # https://matplotlib.org/tutorials/text/mathtext.html latex1 = r'x= \frac{ - b \pm \sqrt {b^2 - 4ac} }{2a}' latex2 = r'\mathcal{A}\mathrm{sin}(2 \omega t)' latex3 = r'I(Y | X)=\sum_{x \in \mathcal{X}, y \in \mathcal{Y}} p(x, y) \log \left(\frac{p(x)}{p(x, y)}\right)' latex4 = r'\Gamma_{\epsilon}(x)=\left[1-e^{-2 \pi \epsilon}\right]^{1-x} \prod_{n=0}^{\infty} \frac{1-\exp (-2 \pi \epsilon(n+1))}{1-\exp (-2 \pi \epsilon(x+n))}' ltx = Latex(latex4, s=1, c='darkblue', bg='', alpha=0.9, usetex=False) ltx.crop(0.3, 0.3) # crop top and bottom 30% ltx.pos(2, 0, 0) ltx.show(axes=1, size=(1400, 700), zoom=1.8)
from vedo import Latex # https://matplotlib.org/tutorials/text/mathtext.html latex1 = r'x= \frac{ - b \pm \sqrt {b^2 - 4ac} }{2a}' latex2 = r'\mathcal{A}\mathrm{sin}(2 \omega t)' latex3 = r'I(Y | X)=\sum_{x \in \mathcal{X}, y \in \mathcal{Y}} p(x, y) \log \left(\frac{p(x)}{p(x, y)}\right)' latex4 = r'\Gamma_{\epsilon}(x)=\left[1-e^{-2 \pi \epsilon}\right]^{1-x} \prod_{n=0}^{\infty} \frac{1-\exp (-2 \pi \epsilon(n+1))}{1-\exp (-2 \pi \epsilon(x+n))}' latex5 = r'\left( \begin{array}{l}{c t^{\prime}} \\ {x^{\prime}} \\ {y^{\prime}} \\ {z^{\prime}}\end{array}\right)=\left( \begin{array}{cccc}{\gamma} & {-\gamma \beta} & {0} & {0} \\ {-\gamma \beta} & {\gamma} & {0} & {0} \\ {0} & {0} & {1} & {0} \\ {0} & {0} & {0} & {1}\end{array}\right) \left( \begin{array}{l}{c t} \\ {x} \\ {y} \\ {z}\end{array}\right)' latex6 = r'\mathrm{CO}_{2}+6 \mathrm{H}_{2} \mathrm{O} \rightarrow \mathrm{C}_{6} \mathrm{H}_{12} \mathrm{O}_{6}+6 \mathrm{O}_{2}' latex7 = r'x \mathrm{(arb. units)}' ltx = Latex(latex4, s=1, c='darkblue', bg='', alpha=0.9, usetex=False, fromweb=False) ltx.crop(0.3, 0.3) # crop top and bottom 30% ltx.pos(2,0,0) ltx.show(axes=1)
from vedo import Latex, show from vedo.pyplot import histogram import numpy as np N = 2000 x = np.random.randn(N) * 1.0 y = np.random.randn(N) * 1.5 # hexagonal binned histogram: histo = histogram( x, y, bins=10, mode='hexbin', xtitle="\sigma_x =1.0", ytitle="\sigma_y =1.5", ztitle="counts", fill=True, cmap='terrain', ) # add a formula: f = r'f(x, y)=A \exp \left(-\left(\frac{\left(x-x_{o}\right)^{2}}' f += r'{2 \sigma_{x}^{2}}+\frac{\left(y-y_{o}\right)^{2}}' f += r'{2 \sigma_{y}^{2}}\right)\right)' formula = Latex(f, c='k', s=1.5).rotateX(90).rotateZ(90).pos(1.5, -2, 1) show(histo, formula, axes=1, viewup='z')