Пример #1
0
 def plot_u(u, x, xv, y, yv, t, n):
     if t[n] == 0:
         time.sleep(2)
     if plot_method == 1:
         plt.mesh(x, y, u, title='t=%g' % t[n], zlim=[-1,1],
              caxis=[-1,1])
     elif plot_method == 2:
         surfc(xv, yv, u, title='t=%g' % t[n], zlim=[-1, 1],
               colorbar=True, colormap=hot(), caxis=[-1,1],
               shading='flat')
     elif plot_method == 3:
         print ('Experimental 3D matplotlib...under development...')
         #plt.clf()
         ax = fig.add_subplot(111, projection='3d')
         u_surf = ax.plot_surface(xv, yv, u, alpha=0.3)
         #ax.contourf(xv, yv, u, zdir='z', offset=-100, cmap=cm.coolwarm)
         #ax.set_zlim(-1, 1)
         # Remove old surface before drawing
         if u_surf is not None:
             ax.collections.remove(u_surf)
         plt.draw()
         time.sleep(1)
     if plot_method > 0:
         time.sleep(0) # pause between frames
         if save_plot:
             filename = 'tmp_%04d.png' % n
             plt.savefig(filename)  # time consuming!
def makeplots( domain, geom, Lx, Lz, value, name, title, ndigits=0, index=None, clim=None, lineOn=False, imgtype=None,):
  points, colors = domain.elem_eval( [ geom, value ], ischeme='bezier3', separate=True )

  with plot.PyPlot( name, ndigits=ndigits, figsize=(5,6), index=index, imgtype=imgtype ) as plt:
    plt.mesh( points, colors, triangulate='bezier', edgecolors='none' )
    plt.title(title)
    plt.xlabel('x [m]')
    plt.ylabel('z [m]')

    plt.xticks( [0, Lx/2.0, Lx], ['0', '300', '600'] )
    plt.yticks( [-0, -0.4*Lz, -0.8*Lz, -Lz], ['0', '400', '800', '1000'] )

    if clim is not None:
      plt.clim(*clim)
    plt.colorbar()

    if lineOn:
      # Only for wedge problem in 2D
      plt.plot( [0, 600],[-400, -500],'k' )
      plt.plot( [0, 600],[-800, -600],'k' )
def makeplots( domain, geom, verts_x, verts_z, value, name, title, ndigits=0, index=None, imgtype=None):
  points, colors = domain.elem_eval( [ geom, value ], ischeme='bezier3', separate=True )

  with plot.PyPlot( name, ndigits=ndigits, index=index, imgtype=imgtype  ) as plt:

      plt.mesh( points, colors, triangulate='bezier', edgecolors='none' )
     
      plt.title(title)
          
      plt.xlabel('x [m]', fontsize=10)
      plt.xticks([0, max(verts_x)/2.0, max(verts_x)], ['0', '2000', '4000'], fontsize=10)
      plt.ylabel('z [m]', fontsize=10)
      plt.yticks([max(verts_z), min(verts_z)], ['0', '1850'], fontsize=10)
      plt.ylim
          
      ax = plt.gca()
      divider = make_axes_locatable(ax)
      cax = divider.append_axes("right", size="5%", pad=0.05)
      cb = plt.colorbar(cax=cax)
      cb.ax.tick_params(labelsize=10)   
Пример #4
0
def makeplots(
    domain,
    geom,
    Lx,
    Lz,
    value,
    name,
    title,
    ndigits=0,
    index=None,
    clim=None,
    lineOn=False,
    imgtype=None,
):
    points, colors = domain.elem_eval([geom, value],
                                      ischeme='bezier3',
                                      separate=True)

    with plot.PyPlot(name,
                     ndigits=ndigits,
                     figsize=(5, 6),
                     index=index,
                     imgtype=imgtype) as plt:
        plt.mesh(points, colors, triangulate='bezier', edgecolors='none')
        plt.title(title)
        plt.xlabel('x [m]')
        plt.ylabel('z [m]')

        plt.xticks([0, Lx / 2.0, Lx], ['0', '300', '600'])
        plt.yticks([-0, -0.4 * Lz, -0.8 * Lz, -Lz],
                   ['0', '400', '800', '1000'])

        if clim is not None:
            plt.clim(*clim)
        plt.colorbar()

        if lineOn:
            # Only for wedge problem in 2D
            plt.plot([0, 600], [-400, -500], 'k')
            plt.plot([0, 600], [-800, -600], 'k')
Пример #5
0
    geom = refgeom + disp

    E = mu['ymod1']
    NU = mu['prat']
    MU = E / (1 + NU)
    LAMBDA = E * NU / (1 + NU) / (1 - 2 * NU)
    stressfunc = -MU * disp.symgrad(refgeom) + LAMBDA * disp.div(
        refgeom) * fn.eye(disp.shape[0])

    if geom.shape == (2, ):
        stressfunc = stressfunc[tuple('xyz'.index(c) for c in stress)]
        mesh, stressdata = case.domain.elem_eval([geom, 1],
                                                 separate=True,
                                                 ischeme='bezier3')
        with _plot('u', name=name, **kwargs) as plt:
            plt.mesh(mesh, stressdata)
            _colorbar(plt, **kwargs)

    elif geom.shape == (3, ):
        nutils.plot.writevtu(name,
                             case.domain,
                             geom,
                             pointdata={
                                 'stress-xx': stressfunc[0, 0],
                                 'stress-xy': stressfunc[0, 1],
                                 'stress-xz': stressfunc[0, 2],
                                 'stress-yy': stressfunc[1, 1],
                                 'stress-yz': stressfunc[1, 2],
                                 'stress-zz': stressfunc[2, 2],
                                 'disp-x': disp[0],
                                 'disp-y': disp[1],
Пример #6
0
import numpy as np
import matplotlib.pyplot as plt

y0 = 0
yn = 1

x0 = -2
xn = 2

x = np.linspace(x0,xn,61)
y = np.linspace(y0,yn,21)

X,Y = np.meshgrid(x,y)

plt.mesh([X,Y],[0])
plt.show()














Пример #7
0
def cmatplot(cmat, ux=None, uy=None, method=1, clevels=None):
    """
    CMATPLOT Plots a cycle matrix, e.g. a rainflow matrix.

    CALL:  cmatplot(F)
        cmatplot(F,method)
        cmatplot(ux,uy,F)
        cmatplot(ux,uy,F,method)

    F      = Cycle matrix (e.g. rainflow matrix) [nxm]
    method = 1: mesh-plot (default)
          2: surf-plot
          3: pcolor-plot    [axis('square')]
          4: contour-plot   [axis('square')]
          5: TechMath-plot  [axis('square')]
          11: From-To, mesh-plot
          12: From-To, surf-plot
          13: From-To, pcolor-plot   [axis('square')]
          14: From-To, contour-plot  [axis('square')]
          15: From-To, TechMath-plot [axis('square')]
    ux     = x-axis (default: 1:m)
    uy     = y-axis (default: 1:n)

    Examples:
    param = [-1 1 64]; u=levels(param);
    F = mktestmat(param,[-0.2 0.2],0.25,1/2);
    cmatplot(F,method=1);
    cmatplot(u,u,F,method=2); colorbar;
    cmatplot(u,u,F,method=3); colorbar;
    cmatplot(u,u,F,method=4);

    close all;

    See also
    --------
    cocc, plotcc
    """

    F = cmat
    shape = np.shape(F)
    if ux is None:
        ux = np.arange(shape[1])  # Antalet kolumner

    if uy is None:
        uy = np.arange(shape[0])  # Antalet rader

    if clevels is None:
        Fmax = np.max(F)
        if method in [5, 15]:
            clevels = Fmax * np.r_[0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1.0]
        else:  # 4, 14
            clevels = Fmax * np.r_[0.005,
                                   0.01,
                                   0.02,
                                   0.05,
                                   0.1,
                                   0.2,
                                   0.4,
                                   0.6,
                                   0.8]

    # Make sure ux and uy are row vectors
    ux = ux.ravel()
    uy = uy.ravel()

    n = len(F)

    from matplotlib import pyplot as plt
    if method == 1:      # mesh
        F = np.flipud(F.T)  # Vrid cykelmatrisen for att plotta rett
        plt.mesh(ux, np.fliplr(uy), F)
        plt.xlabel('min')
        plt.ylabel('Max')
        # view(-37.5-90,30);
        # v = axis;
        # plt.axis([min(ux) max(ux) min(uy) max(uy) v[5:6]]);
    elif method == 2:  # surf
        F = np.flipud(F.T)  # Vrid cykelmatrisen for att plotta rett
        plt.surf(ux, np.fliplr(uy), F)
        plt.xlabel('min')
        plt.ylabel('Max')