# 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 vtkplotter.dolfin import plot from vtkplotter 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, text='Load') ####################################################################### #import matplotlib.pyplot as plt #plot(w) #plt.plot(y, 50*w_line, 'k', linewidth=2) # magnify w #plt.plot(y, p_line, 'b--', linewidth=2) #plt.grid(True) #plt.xlabel('$y$') #plt.legend(['Deflection ($\\times 50$)', 'Load'], loc='upper left')
""" 2D histogram with hexagonal binning. """ print(__doc__) from vtkplotter import Plotter, histogram2D, Points, Latex import numpy as np vp = Plotter(axes=1, verbose=0, bg="w") vp.xtitle = "x gaussian, s=1.0" vp.ytitle = "y gaussian, s=1.5" vp.ztitle = "dN/dx/dy" N = 20000 x = np.random.randn(N) * 1.0 y = np.random.randn(N) * 1.5 histo = histogram2D(x, y, c="dr", bins=15, fill=False) pts = Points([x, y, np.zeros(N)], c="black", alpha=0.1) f = r'f(x, y)=A \exp \left(-\left(\frac{\left(x-x_{o}\right)^{2}}{2 \sigma_{x}^{2}}+\frac{\left(y-y_{o}\right)^{2}}{2 \sigma_{y}^{2}}\right)\right)' formula = Latex(f, c='k', s=2).rotateZ(90).pos(5, -2, 1) vp.show(histo, pts, formula, viewup="z")
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) 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 grd.cellColors(V.ravel(), cmap='ocean_r').mapCellsToPoints() newpts = grd.points() newpts[:, 2] = grd.getPointArray('CellScalars') * 25 # assign z
from vtkplotter import Latex, Point, show # 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)}' l = Latex(latex4, s=1, c='white', bg='', alpha=0.9, usetex=False, fromweb=False) l.crop(0.3, 0.3) # crop top and bottom 30% l.pos(2, 0, 0) p = Point() box = l.box() # return the bounding box of an actor show(p, l, box, axes=8)
from vtkplotter import Latex, Cube, Point, show # 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)}' p = Point() c = Cube().wire() l = Latex(latex5, s=1, c='white', bg='', alpha=0.9, fromweb=False).addPos(4, 0, -1) show(p, c, l, axes=8)
from vtkplotter 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)