Mesh: Basic: PlotImageΒΆ

You can use M.PlotImage to plot images on all of the Meshes.

(Source code, png, hires.png, pdf)

../../_images/Mesh_Basic_PlotImage-1.png
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from SimPEG import Mesh, Utils
import matplotlib.pyplot as plt


def run(plotIt=True):
    """
        Mesh: Basic: PlotImage
        ======================

        You can use M.PlotImage to plot images on all of the Meshes.


    """
    M = Mesh.TensorMesh([32, 32])
    v = Utils.ModelBuilder.randomModel(M.vnC, seed=789)
    v = Utils.mkvc(v)

    O = Mesh.TreeMesh([32, 32])
    O.refine(1)

    def function(cell):
        if (
            cell.center[0] < 0.75 and cell.center[0] > 0.25 and
            cell.center[1] < 0.75 and cell.center[1] > 0.25
        ):
            return 5
        if (
            cell.center[0] < 0.9 and cell.center[0] > 0.1 and
            cell.center[1] < 0.9 and cell.center[1] > 0.1
        ):
            return 4
        return 3
    O.refine(function)

    P = M.getInterpolationMat(O.gridCC, 'CC')

    ov = P * v

    if not plotIt:
        return

    fig, axes = plt.subplots(1, 2, figsize=(10, 5))

    out = M.plotImage(v, grid=True, ax=axes[0])
    cb = plt.colorbar(out[0], ax=axes[0])
    cb.set_label("Random Field")
    axes[0].set_title('TensorMesh')

    out = O.plotImage(ov, grid=True, ax=axes[1], clim=[0, 1])
    cb = plt.colorbar(out[0], ax=axes[1])
    cb.set_label("Random Field")
    axes[1].set_title('TreeMesh')


if __name__ == '__main__':
    run()
    plt.show()