<commit_before>import numpy as np
from matplotlib import pyplot as plt
from os import path


def plot_edge_length_distributions(shape_name,
                                   scale_edge_length_PLY,
                                   rounded_edge_length_PLY,
                                   results_foldername):
    min_len_nt = min(rounded_edge_length_PLY)
    bins_for_hist = range(min_len_nt, max(rounded_edge_length_PLY) + 3, 1)
    bins_for_plotting = [x - 0.25 for x in bins_for_hist[:-1]]

    # TODO: if there are too many bins (400-ish or more), then things get
    # weird.  You can drastically increase the resolution to see what's going
    # on.  Adding a bit more buffer on the left side of the graph helps, too.
    # See sample shape 37_enneagonal_trapezohedron.ply as an example.

    fig_31 = plt.figure(0, figsize=(16, 8))
    fig_31.clf()
    y31 = np.histogram(scale_edge_length_PLY, bins=bins_for_hist)[0]
    plt.bar(bins_for_plotting, y31, width=0.5)
    plt.xlim((min_len_nt - 0.5, max(rounded_edge_length_PLY) + 1.5))
    plt.ylim((0, max(y31) + 1))
    plt.title('Minimum edge length {} bp'.format(min_len_nt))
    plt.xlabel('Edge length (bp)')
    plt.ylabel('Number of edges')
    plt.xticks(bins_for_hist)

    fig_32 = plt.figure(1, figsize=(16, 8))
    fig_32.clf()
    y32 = np.histogram(rounded_edge_length_PLY, bins=bins_for_hist)[0]
    bins_a = [x - 0.125 for x in bins_for_plotting]
    bins_b = [x + 0.38 for x in bins_for_plotting]
    plt.bar(bins_a, y31, width=0.25, color='b')
    plt.bar(bins_b, y32, width=0.25, color='r')

    plt.xlim((min_len_nt - 0.5, max(rounded_edge_length_PLY) + 1.5))
    plt.ylim((0, max(max(y31) + 1, 1)))
    plt.title('Edges rounded to nearest 10.5 bp')
    plt.xlabel('Edge length (bp)')
    plt.ylabel('Number of edges')
    plt.xticks(bins_for_hist)

    shape_name_with_len = shape_name + '_{}_'.format(min_len_nt)
    base_filename = path.join(results_foldername, shape_name_with_len)
    fig_31.savefig(base_filename + 'min_edge_length_dist.png',
                   bbox_inches='tight')
    fig_32.savefig(base_filename + 'edges_rounded_to_10_5.png',
                   bbox_inches='tight')<commit_msg>Letting tick markers be chosen automatically (else we forcd things to look very messy when there is a large difference in edge lengths.<commit_after>import numpy as np
from matplotlib import pyplot as plt
from os import path


def plot_edge_length_distributions(shape_name,
                                   scale_edge_length_PLY,
                                   rounded_edge_length_PLY,
                                   results_foldername):
    min_len_nt = min(rounded_edge_length_PLY)
    bins_for_hist = range(min_len_nt, max(rounded_edge_length_PLY) + 3, 1)
    bins_for_plotting = [x - 0.25 for x in bins_for_hist[:-1]]

    # TODO: if there are too many bins (400-ish or more), then things get
    # weird.  You can drastically increase the resolution to see what's going
    # on.  Adding a bit more buffer on the left side of the graph helps, too.
    # See sample shape 37_enneagonal_trapezohedron.ply as an example.

    fig_31 = plt.figure(0, figsize=(16, 8))
    fig_31.clf()
    y31 = np.histogram(scale_edge_length_PLY, bins=bins_for_hist)[0]
    plt.bar(bins_for_plotting, y31, width=0.5)
    plt.xlim((min_len_nt - 0.5, max(rounded_edge_length_PLY) + 1.5))
    plt.ylim((0, max(y31) + 1))
    plt.title('Minimum edge length {} bp'.format(min_len_nt))
    plt.xlabel('Edge length (bp)')
    plt.ylabel('Number of edges')
    # plt.xticks(bins_for_hist)

    fig_32 = plt.figure(1, figsize=(16, 8))
    fig_32.clf()
    y32 = np.histogram(rounded_edge_length_PLY, bins=bins_for_hist)[0]
    bins_a = [x - 0.125 for x in bins_for_plotting]
    bins_b = [x + 0.38 for x in bins_for_plotting]
    plt.bar(bins_a, y31, width=0.25, color='b')
    plt.bar(bins_b, y32, width=0.25, color='r')

    plt.xlim((min_len_nt - 0.5, max(rounded_edge_length_PLY) + 1.5))
    plt.ylim((0, max(max(y31) + 1, 1)))
    plt.title('Edges rounded to nearest 10.5 bp')
    plt.xlabel('Edge length (bp)')
    plt.ylabel('Number of edges')
    # plt.xticks(bins_for_hist)

    shape_name_with_len = shape_name + '_{}_'.format(min_len_nt)
    base_filename = path.join(results_foldername, shape_name_with_len)
    fig_31.savefig(base_filename + 'min_edge_length_dist.png',
                   bbox_inches='tight')
    fig_32.savefig(base_filename + 'edges_rounded_to_10_5.png',
                   bbox_inches='tight')
{'fraction_non_alphanumeric': 0.11254448398576512, 'fraction_numerical': 0.03603202846975089, 'mean_word_length': 3.0881818181818184, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '332020', 'n_tokens_mistral': 1770, 'n_tokens_neox': 1621, 'n_words': 363}