<commit_before><commit_msg>missing transect_data.py from ats-demos<commit_after>"""Plots 2D data on quadrilaterals using matplotlib.
"""

import sys,os
import numpy as np
import matplotlib.collections
from matplotlib import pyplot as plt
import h5py
import mesh
import colors

def plot(dataset, ax, cax=None, vmin=None, vmax=None, cmap="jet",
         label=None,
    mesh_filename="visdump_mesh.h5", directory="."):
    """Draws a dataset on an ax."""
    if vmin is None:
        vmin = dataset.min()
    if vmax is None:
        vmax = dataset.max()

    # get the mesh and collapse to 2D
    etype, coords, conn = mesh.meshElemXYZ(filename=mesh_filename, directory=directory)
    if etype is not 'HEX':
        raise RuntimeError("Only works for Hexs")

    coords2 = np.array([[coords[i][0::2] for i in c if coords[i][1] == 0.0] for c in conn])
    assert coords2.shape[2] == 2
    assert coords2.shape[1] == 4

    polygons = matplotlib.collections.PolyCollection(coords2, edgecolor='k', cmap=cmap)
    polygons.set_array(dataset)
    polygons.set_clim(vmin,vmax)
    ax.add_collection(polygons)

    xmin = min(c[0] for c in coords.itervalues())
    xmax = max(c[0] for c in coords.itervalues())
    zmin = min(c[2] for c in coords.itervalues())
    zmax = max(c[2] for c in coords.itervalues())

    ax.set_xlim(xmin,xmax)
    ax.set_ylim(zmin,zmax)

    if cax is not None:
        cb = plt.colorbar(polygons, cax=cax)
        if label is not None:
            cb.set_label(label)
        
    return ((xmin,xmax),(zmin,zmax))
    
{'fraction_non_alphanumeric': 0.12272727272727273, 'fraction_numerical': 0.013636363636363636, 'mean_word_length': 3.268698060941828, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5368787', 'n_tokens_mistral': 582, 'n_tokens_neox': 569, 'n_words': 148}