示例#1
0
def plot_configuration_grid(snapshots: HoomdFrame,
                            categories: np.ndarray,
                            max_frames=3,
                            remove_styling=False) -> Figure:
    factors = np.unique(categories).astype(str)
    if len(factors) < 10:
        colormap = palettes.Category10_10
    else:
        colormap = palettes.Category20_20
    cluster_assignment = np.split(categories, len(snapshots))

    grid = []
    for snap, cluster, i in zip(snapshots, cluster_assignment, count()):
        if i > max_frames:
            break
        fig = plot_frame(
            snap,
            order_list=cluster,
            categorical_colour=True,
            colormap=colormap,
            factors=factors,
        )

        if remove_styling:
            fig = style_snapshot(fig)

        grid.append(fig)

    return _plot_grid(grid)
示例#2
0
def plot_clustering(algorithm, X, snapshots, fit=True):
    if fit:
        clusters = algorithm.fit_predict(X)
    else:
        clusters = algorithm.predict(X)
    cluster_assignment = np.split(clusters, len(snapshots))
    fig = plot_grid([
        plot_frame(snap, order_list=cluster, categorical_colour=True)
        for snap, cluster in zip(snapshots, cluster_assignment)
    ])
    return fig
示例#3
0
def plot_labelled_config(snapshot: HoomdFrame) -> Figure:
    """Plot an input configuration indicating the labelling scheme.

    This plots the configuration with an overlay indicating the regions in which
    particles are classified as liquid (blue) and the regions where they are classified
    as crystal (red).

    Args:
        snapshot: The snapshot configuration to display

    """
    x_len, y_len = snapshot.box[:2]
    cell, liq, crys = cell_regions(x_len, y_len)

    fig = plot_frame(snapshot)
    # use the canvas backend which supports transparency and other effects.
    fig.output_backend = "canvas"

    # Plot the liquid region, being the cell boundary with a hole in the middle
    fig.multi_polygons(
        xs=[[[cell[0], liq[0]]]],
        ys=[[[cell[1], liq[1]]]],
        fill_alpha=0.3,
        fill_color="blue",
        line_color=None,
    )

    # Plot the crystal region being a central rectangle
    fig.multi_polygons(
        xs=[[[crys[0]]]],
        ys=[[[crys[1]]]],
        fill_alpha=0.3,
        fill_color="red",
        line_color=None,
    )

    return style_snapshot(fig)
示例#4
0
def plot_snapshots(snapshots):
    return plot_grid([plot_frame(snap) for snap in snapshots])
示例#5
0
def plot_snapshots(snapshots: HoomdFrame) -> Figure:
    """Plot a collection of snapshots as a grid."""
    return _plot_grid([style_snapshot(plot_frame(snap)) for snap in snapshots])