Пример #1
0
 def __init__(self, ax, *args, **kwargs):
     """
     Draw triangular grid contour lines or filled regions,
     depending on whether keyword arg 'filled' is False
     (default) or True.
     The first argument of the initializer must be an axes
     object.  The remaining arguments and keyword arguments
     are described in TriContourSet.tricontour_doc.
     """
     ContourSet.__init__(self, ax, *args, **kwargs)
Пример #2
0
    def __init__(self, ax, *args, **kwargs):
        """
        Draw triangular grid contour lines or filled regions,
        depending on whether keyword arg 'filled' is False
        (default) or True.

        The first argument of the initializer must be an axes
        object.  The remaining arguments and keyword arguments
        are described in the docstring of `tricontour`.
        """
        ContourSet.__init__(self, ax, *args, **kwargs)
Пример #3
0
def test_contour_manual():
    # Manually specifying contour lines/polygons to plot.
    from matplotlib.contour import ContourSet

    fig, ax = plt.subplots(figsize=(4, 4))
    cmap = 'viridis'

    # Segments only (no 'kind' codes).
    lines0 = [[[2, 0], [1, 2], [1, 3]]]  # Single line.
    lines1 = [[[3, 0], [3, 2]], [[3, 3], [3, 4]]]  # Two lines.
    filled01 = [[[0, 0], [0, 4], [1, 3], [1, 2], [2, 0]]]
    filled12 = [[[2, 0], [3, 0], [3, 2], [1, 3], [1, 2]],  # Two polygons.
                [[1, 4], [3, 4], [3, 3]]]
    ContourSet(ax, [0, 1, 2], [filled01, filled12], filled=True, cmap=cmap)
    ContourSet(ax, [1, 2], [lines0, lines1], linewidths=3, colors=['r', 'k'])

    # Segments and kind codes (1 = MOVETO, 2 = LINETO, 79 = CLOSEPOLY).
    segs = [[[4, 0], [7, 0], [7, 3], [4, 3], [4, 0],
             [5, 1], [5, 2], [6, 2], [6, 1], [5, 1]]]
    kinds = [[1, 2, 2, 2, 79, 1, 2, 2, 2, 79]]  # Polygon containing hole.
    ContourSet(ax, [2, 3], [segs], [kinds], filled=True, cmap=cmap)
    ContourSet(ax, [2], [segs], [kinds], colors='k', linewidths=3)
Пример #4
0
def draw_mncontour(self, x, y, nsigma=2, numpoints=20):
    from matplotlib import pyplot as plt
    from matplotlib.contour import ContourSet

    c_val = []
    c_pts = []
    for sigma in range(1, nsigma + 1):
        pts = self.mncontour(x, y, numpoints, sigma)[2]
        # close curve
        pts.append(pts[0])
        c_val.append(sigma)
        c_pts.append([pts])  # level can have more than one contour in mpl
    cs = ContourSet(plt.gca(), c_val, c_pts)
    plt.clabel(cs, inline=1, fontsize=10)
    plt.xlabel(x)
    plt.ylabel(y)
    return cs
Пример #5
0
# Contour lines for each level are a list/tuple of polygons.
lines0 = [[[0,0],[0,4]]]
lines1 = [[[2,0],[1,2],[1,3]]]
lines2 = [[[3,0],[3,2]], [[3,3],[3,4]]]  # Note two lines.

# Filled contours between two levels are also a list/tuple of polygons.
# Points can be ordered clockwise or anticlockwise.
filled01 = [[[0,0],[0,4],[1,3],[1,2],[2,0]]]
filled12 = [[[2,0],[3,0],[3,2],[1,3],[1,2]],   # Note two polygons.
             [[1,4],[3,4],[3,3]]]


plt.figure()

# Filled contours using filled=True.
cs = ContourSet(plt.gca(), [0,1,2], [filled01, filled12], filled=True, cmap=cm.bone)
cbar = plt.colorbar(cs)

# Contour lines (non-filled).
lines = ContourSet(plt.gca(), [0,1,2], [lines0, lines1, lines2], cmap=cm.cool,
                   linewidths=3)
cbar.add_lines(lines)

plt.axis([-0.5, 3.5, -0.5, 4.5])
plt.title('User-specified contours')


# Multiple filled contour lines can be specified in a single list of polygon
# vertices along with a list of vertex kinds (code types) as described in the
# Path class.  This is particularly useful for polygons with holes.
# Here a code type of 1 is a MOVETO, and 2 is a LINETO.
Пример #6
0
    os.remove(f)

for i in range(300):
    ax.clear()
    ax.set_xlim(-print_platform_width / 2, print_platform_width / 2)
    ax.set_ylim(-print_platform_depth / 2, print_platform_depth / 2)
    ax.get_xaxis().set_visible(False)
    ax.get_yaxis().set_visible(False)

    polygons = glob.glob(f'test/csv/slice{i}_*.csv')

    if len(polygons) == 0:
        continue
    '''
    contours = list(map(lambda p: np.loadtxt(p).tolist(), polygons))
    commands = [list(map(lambda i: 1 if i == 0 else 2, range(len(contour)))) for contour in contours]
    cs = ContourSet(ax, [0, 1], [[np.concatenate(contours).tolist()]], [[np.concatenate(commands).tolist()]], filled=True)
    '''
    contours = list(map(lambda p: [np.loadtxt(p).tolist()], polygons))
    commands = [[
        list(map(lambda i: 1 if i == 0 else 2, range(len(contour[0]))))
    ] for contour in contours]
    levels = list(range(len(contours)))
    cs = ContourSet(ax, levels, contours, commands, filled=False)
    '''
    for polygon in polygons:
        vertices = np.loadtxt(polygon)
        plt.fill(vertices[:,0], vertices[:,1], 'black')
    '''
    plt.subplots_adjust(left=0, right=1, top=1, bottom=0)
    plt.savefig(f'test/img/slice{i}.png')
Пример #7
0
def log_plot_combo(logs, polygons, depths):
    logs = logs.sort_values(by='Depth')
    top = logs.Depth.min()
    bot = logs.Depth.max()

    f, ax = plt.subplots(nrows=1, ncols=7, figsize=(14, 8))
    ax[0].plot(logs.GR, logs.Depth, color='green')
    ax[1].plot(logs.CNPOR, logs.Depth, color='red')
    ax[2].plot(logs.DT, logs.Depth, color='black')
    ax[3].plot(logs.MELCAL, logs.Depth, color='blue')
    ax[4].plot(logs.RHOB, logs.Depth, color='c')
    ax[5].plot(logs.Vsh, logs.Depth, color='m')

    ContourSet(ax[6], [0, 1, 2, 3, 4],
               [polygon1, polygon2, polygon3, polygon4],
               filled=True,
               colors=('blue', 'red', 'yellow', 'green'))

    # Legend
    plt.plot([], [], color='b', label='Water', linewidth=3)
    plt.plot([], [], color='r', label='Shale', linewidth=3)
    plt.plot([], [], color='y', label='Sand', linewidth=3)
    plt.plot([], [], color='g', label='Carbonate', linewidth=3)
    plt.legend()

    for i in range(len(ax)):
        ax[i].set_ylim(top, bot)
        ax[i].invert_yaxis()
        ax[i].grid()

    ax[0].set_ylabel("Depth (ft)")

    ax[0].set_xlabel("GR")
    ax[0].set_xlim(logs.GR.min(), logs.GR.max())

    ax[1].set_xlabel("CNPOR")
    ax[1].set_xlim(logs.CNPOR.min(), logs.CNPOR.max())

    ax[2].set_xlabel("DT")
    ax[2].set_xlim(logs.DT.min(), logs.DT.max())

    ax[3].set_xlabel("MELCAL")
    ax[3].set_xlim(logs.MELCAL.min(), logs.MELCAL.max())

    ax[4].set_xlabel("RHOB")
    ax[4].set_xlim(logs.RHOB.min(), logs.RHOB.max())

    ax[5].set_xlabel("Vsh")
    ax[5].set_xlim(logs.Vsh.min(), logs.Vsh.max())

    ax[6].set_xlabel("Fraction 4")
    ax[6].set_xlim(0, 1)

    ax[1].set_yticklabels([])
    ax[2].set_yticklabels([])
    ax[3].set_yticklabels([])
    ax[4].set_yticklabels([])
    ax[5].set_yticklabels([])
    ax[6].set_yticklabels([])

    f.suptitle('Well: KOOCHEL MOUNTAIN #1', fontsize=14, y=0.94)
Пример #8
0
polygon1 = [max_coord + min_coord + fraction1]
polygon2 = [fraction1 + fraction2[::-1]]
polygon3 = [fraction2 + fraction3[::-1]]
polygon4 = [fraction3 + fraction4[::-1]]
polygons = [polygon1, polygon2, polygon3, polygon4]

# ---  ===  ---  ===  ---  ===  ---  ===  ---  ===  ---  ===
# ---  ===  ---  ===  ---  ===  ---  ===  ---  ===  ---  ===

# The rest is the mechanics of plotting

# The lines below create a standalone plot of the polygons.
fig, ax = plt.subplots()

ContourSet(ax, [0, 1, 2, 3, 4], [polygon1, polygon2, polygon3, polygon4],
           filled=True,
           colors=(mycolors))

# Legend
plt.plot([], [], color='b', label='Water', linewidth=3)
plt.plot([], [], color='r', label='Shale', linewidth=3)
plt.plot([], [], color='y', label='Sand', linewidth=3)
plt.plot([], [], color='g', label='Carbonate', linewidth=3)
plt.legend()

ax.set_ylim(min_depth, max_depth)
ax.invert_yaxis()

ax.set(xlim=(0, 1), ylim=(max_depth, min_depth), title='Fraction Panel')
plt.show()