コード例 #1
0
def plotmesh(Th, **kwargs):
    assert issiMesh(Th), "First argument must be a siMesh object"
    d = kwargs.pop('d', Th.d)
    latex = kwargs.pop('latex', True)
    all_labels = Th.sThlab[Th.find(d)]
    labels = np.intersect1d(kwargs.pop('labels', all_labels), all_labels)
    if np.isscalar(labels):
        labels = [labels]
    legend = kwargs.pop('legend', False)
    if len(labels) == 0:
        print('No submesh found!')
        return
    #plt.rc('text', usetex=True, text.latex.unicode)
    #fig = plt.gcf()
    Legend_handle = []
    Labels = []
    LabName = LabelBaseName(Th, d)
    for l in labels:
        k = Th.find(d, labels=[l])
        if len(k) == 1:
            lh = sME.plotmesh(Th.sTh[k[0]], **kwargs)
            if legend:
                if isinstance(lh, list):
                    lh = lh[0]
                if isinstance(
                        lh, Poly3DCollection
                ):  # BUG: plt.legend does not accept Poly3DCollection as input
                    lkwargs = kwargs
                    color = check_color(
                        lkwargs.pop('color', Th.sTh[k[0]].color))
                    edgecolor = check_color(lkwargs.pop('edgecolor', 'White'))
                    facecolor = check_color(lkwargs.pop('facecolor', color))
                    Legend_handle.append(
                        Patch(facecolor=facecolor,
                              edgecolor=edgecolor,
                              **kwargs))
                else:
                    Legend_handle.append(lh)
                if latex:
                    Labels.append(r'$%s_{%d}$' % (LabName, l))
                else:
                    Labels.append(mesh_label(Th.sTh[k[0]]))

    #ax=fig.axes[0]
    #ax.set_axis_off()
    #ax.set_axis_bgcolor('None')
    if legend:
        plt.legend(Legend_handle,
                   Labels,
                   loc='best',
                   ncol=int(len(Legend_handle) / 10) + 1).draggable()
    #coef=1.0
    #m=min(Th.bbox);M=max(Th.bbox)
    #if Th.dim==3:
    #ax.set_zlim(m*coef,M*coef)
    #ax.set_xlim(m*coef,M*coef)
    #ax.set_ylim(m*coef,M*coef)
    #ax.set_aspect('equal')
    set_axes(plt.gca(), Th.bbox)
    return Legend_handle
コード例 #2
0
def plot_SubTh1simp2D(q, me, u, **kwargs):
    lim = kwargs.pop('lim', True)
    plane = kwargs.pop('plane', True)
    vmin = kwargs.pop('vmin', np.min(u))
    vmax = kwargs.pop('vmax', np.max(u))
    fig = plt.gcf()
    if plane:
        ax = plt.gca()
        coll = ax.add_collection(
            LineCollection(q[me],
                           array=np.mean(u[me], axis=1),
                           norm=matplotlib.colors.Normalize(vmin=vmin,
                                                            vmax=vmax),
                           **kwargs))
        if lim:
            box = np.array([
                np.min(q[:, 0]),
                np.max(q[:, 0]),
                np.min(q[:, 1]),
                np.max(q[:, 1])
            ])
            set_axes(ax, box)
        return coll
    nq = q.shape[0]
    assert isinstance(u, np.ndarray) and u.shape[0] == nq
    Q = np.concatenate((q, u.reshape((nq, 1))), axis=1)
    return plot_SubTh1simp3D(Q, me, u, vmin=vmin, vmax=vmax, lim=lim, **kwargs)
コード例 #3
0
def plotiso(Th, u, **kwargs):
    assert issiMesh(Th), "First argument must be a siMesh object"
    assert (Th.dim == 2 and Th.d == 2)
    kwargs['vmin'] = kwargs.get('vmin', min(u))
    kwargs['vmax'] = kwargs.get('vmax', max(u))
    labels = kwargs.pop('labels', Th.sThlab[Th.find(Th.d)])
    merge = kwargs.pop('merge', True)

    colormap = kwargs.pop('colormap', 'viridis')
    kwargs['cmap'] = kwargs.pop('map', plt.cm.get_cmap(name=colormap))
    if merge:
        (q, me, toGlobal) = Th.get_mesh(d=Th.d, labels=labels)
        pp = plt4sim.plotiso(q, me, u[toGlobal], **kwargs)
        set_axes(plt.gca(), Th.bbox)
        return pp

    if isinstance(labels, int):
        labels = [labels]
    handles = []
    for l in labels:
        k = Th.find(Th.d, labels=[l])
        if len(k) == 1:
            h = sME.plotiso(Th.sTh[k[0]], u, **kwargs)
            handles.append(h)
    set_axes(plt.gca(), Th.bbox)
    return handles
コード例 #4
0
def plot_SubTh2simp3D(q, me, u, **kwargs):
    vmin = kwargs.pop('vmin', np.min(u))
    vmax = kwargs.pop('vmax', np.max(u))
    fig = plt.gcf()
    if len(fig.axes) > 0:
        ax = fig.axes[0]
    else:
        ax = fig.gca(projection='3d')
    U = np.mean(u[me], axis=1).reshape((me.shape[0], ))
    coll = ax.add_collection(
        Poly3DCollection(q[me],
                         array=U,
                         norm=matplotlib.colors.Normalize(vmin=vmin,
                                                          vmax=vmax),
                         **kwargs))
    box = np.array([
        np.min(q[:, 0]),
        np.max(q[:, 0]),
        np.min(q[:, 1]),
        np.max(q[:, 1]),
        np.min(q[:, 2]),
        np.max(q[:, 2])
    ])
    set_axes(ax, box)
    return coll
コード例 #5
0
def plotmesh_SubTh3simp3D(q, me, **kwargs):
    lim = kwargs.pop('lim', True)
    cut_planes = kwargs.pop('cut_planes', [])
    ME = cutMeshElements(q, me, cut_planes)
    nq = q.shape[0]
    fig = plt.gcf()
    if len(fig.axes) > 0:
        ax = fig.axes[0]
    else:
        ax = fig.gca(projection='3d')
    Q = np.concatenate(
        (q[ME[:, [0, 1]]], q[ME[:, [0, 2]]], q[ME[:, [0, 3]]],
         q[ME[:, [1, 2]]], q[ME[:, [1, 3]]], q[ME[:,
                                                  [2, 3]]]))  #.swapaxes(0,1)
    coll = ax.add_collection(Line3DCollection(
        Q, **kwargs))  # linewidths=0.4, linestyles=':')
    if lim:
        box = np.array([
            np.min(q[:, 0]),
            np.max(q[:, 0]),
            np.min(q[:, 1]),
            np.max(q[:, 1]),
            np.min(q[:, 2]),
            np.max(q[:, 2])
        ])
        set_axes(ax, box)
    return coll
コード例 #6
0
def plotmesh_SubTh2simp3D(q, me, **kwargs):
    lim = kwargs.pop('lim', True)
    color = check_color(kwargs.pop('color', 'Blue'))
    kwargs['edgecolor'] = check_color(kwargs.pop('edgecolor', color))
    kwargs['facecolor'] = check_color(kwargs.pop('facecolor', color))
    #if facecolor is None:
    #facecolor='none'
    cut_planes = kwargs.pop('cut_planes', [])
    ME = cutMeshElements(q, me, cut_planes)
    fig = plt.gcf()
    if len(fig.axes) > 0:
        ax = fig.axes[0]
    else:
        ax = fig.gca(projection='3d')
    polys = Poly3DCollection(q[ME], **kwargs)
    #polys.set_facecolor(facecolor)
    coll = ax.add_collection(
        polys)  # BUG: with alpha=... don't work with ax.add_collection3d
    if lim:
        box = np.array([
            np.min(q[:, 0]),
            np.max(q[:, 0]),
            np.min(q[:, 1]),
            np.max(q[:, 1]),
            np.min(q[:, 2]),
            np.max(q[:, 2])
        ])
        set_axes(ax, box)
    return coll
コード例 #7
0
def plotmesh_SubTh2simp2D(q, me, **kwargs):
    lim = kwargs.pop('lim', True)
    color = check_color(kwargs.pop('color', 'Blue'))
    kwargs['edgecolor'] = check_color(kwargs.pop('edgecolor', color))
    facecolor = check_color(kwargs.pop('facecolor', None))
    if facecolor is None:
        facecolor = 'none'
    z = kwargs.pop('z', None)
    if z is None:
        fig = plt.gcf()
        ax = fig.gca()
        polys = PolyCollection(q[me], **kwargs)
        polys.set_facecolor(facecolor)
        coll = ax.add_collection(polys)
        if lim:
            box = np.array([
                np.min(q[:, 0]),
                np.max(q[:, 0]),
                np.min(q[:, 1]),
                np.max(q[:, 1])
            ])
            set_axes(ax, box)
        return coll
        #return plt.triplot(q[:,0],q[:,1],triangles=me,**kwargs)
    nq = q.shape[0]
    assert isinstance(z, np.ndarray) and z.shape[0] == nq
    z.resize((nq, 1))
    return plotmesh_SubTh2simp3D(np.concatenate((q, z), axis=1),
                                 me,
                                 lim=lim,
                                 **kwargs)
コード例 #8
0
def plotmesh_SubTh1simp2D(q, me, **kwargs):
    lim = kwargs.pop('lim', True)
    z = kwargs.pop('z', None)
    nme = me.shape[0]
    nq = q.shape[0]
    fig = plt.gcf()
    if z is None:
        ax = fig.gca()
        coll = ax.add_collection(LineCollection(q[me], **kwargs))
        box = np.array([
            np.min(q[:, 0]),
            np.max(q[:, 0]),
            np.min(q[:, 1]),
            np.max(q[:, 1])
        ])
        set_axes(ax, box)
        return coll
    assert isinstance(z, np.ndarray) and z.shape[0] == nq
    z.resize((nq, 1))
    return plotmesh_SubTh1simp3D(np.concatenate((q, z), axis=1), me, **kwargs)
コード例 #9
0
def plot_SubTh3simp3D(q, me, u, **kwargs):
    s = kwargs.pop('s', 1)
    kwargs['vmin'] = kwargs.get('vmin', np.min(u))
    kwargs['vmax'] = kwargs.get('vmax', np.max(u))

    fig = plt.gcf()
    if len(fig.axes) > 0:
        ax = fig.axes[0]
    else:
        ax = fig.gca(projection='3d')
    sc = ax.scatter3D(q[:, 0], q[:, 1], q[:, 2], s=s, c=u, **kwargs)
    box = np.array([
        np.min(q[:, 0]),
        np.max(q[:, 0]),
        np.min(q[:, 1]),
        np.max(q[:, 1]),
        np.min(q[:, 2]),
        np.max(q[:, 2])
    ])
    set_axes(ax, box)
    return sc
コード例 #10
0
def plotmesh_SubTh1simp3D(q, me, **kwargs):
    lim = kwargs.pop('lim', True)
    nme = me.shape[0]
    nq = q.shape[0]
    fig = plt.gcf()
    if len(fig.axes) > 0:
        ax = fig.axes[0]
    else:
        ax = fig.gca(projection='3d')
    coll = ax.add_collection(Line3DCollection(q[me], **kwargs))
    if lim:
        box = np.array([
            np.min(q[:, 0]),
            np.max(q[:, 0]),
            np.min(q[:, 1]),
            np.max(q[:, 1]),
            np.min(q[:, 2]),
            np.max(q[:, 2])
        ])
        set_axes(ax, box)
    return coll
コード例 #11
0
def plot(Th, u, **kwargs):
    assert issiMesh(Th), "First argument must be a siMesh object"
    d = kwargs.pop('d', Th.d)
    kwargs['vmin'] = kwargs.get('vmin', min(u))  #;kwargs['vmin']=vmin
    kwargs['vmax'] = kwargs.get('vmax', max(u))  #;kwargs['vmax']=vmax
    labels = kwargs.pop('labels', Th.sThlab[Th.find(d)])
    merge = kwargs.pop('merge', True)
    colormap = kwargs.pop('colormap', 'viridis')
    kwargs['cmap'] = kwargs.pop('cmap', plt.cm.get_cmap(name=colormap))
    if merge:
        (q, me, toGlobal) = Th.get_mesh(d=d, labels=labels)
        pp = plt4sim.plot(q, me, u[toGlobal], **kwargs)
        set_axes(plt.gca(), Th.bbox)
        return pp

    if isinstance(labels, int):
        labels = [labels]

    handles = []
    for l in labels:
        k = Th.find(d, labels=[l])
        if len(k) == 1:
            h = sME.plot(Th.sTh[k[0]], u, **kwargs)
            handles.append(h)
    #ax=plt.gca()
    set_axes(plt.gca(), Th.bbox)
    #coef=1.0
    #m=min(Th.bbox);M=max(Th.bbox)
    #fig = plt.gcf()
    #ax=fig.axes[0]
    #if Th.dim==3:
    #ax.set_zlim(m*coef,M*coef)
    #ax.set_xlim(m*coef,M*coef)
    #ax.set_ylim(m*coef,M*coef)
    #ax.set_aspect('equal')
    return handles