X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=plot_frequency_histogram.py;fp=plot_frequency_histogram.py;h=d4a929786760dd9aafd643aa82e02518abf823e1;hb=3d8f7067b9c3a48ef140d7cff834d18ee91f58b3;hp=0000000000000000000000000000000000000000;hpb=21c390a77d42729afa23844ef2f1295106bed3de;p=cipher-tools.git diff --git a/plot_frequency_histogram.py b/plot_frequency_histogram.py new file mode 100644 index 0000000..d4a9297 --- /dev/null +++ b/plot_frequency_histogram.py @@ -0,0 +1,15 @@ +import matplotlib.pyplot as plt + +def plot_frequency_histogram(freqs, sort_key=None): + x = range(len(freqs)) + y = [freqs[l] for l in sorted(freqs, key=sort_key)] + f = plt.figure() + ax = f.add_axes([0.1, 0.1, 0.9, 0.9]) + ax.bar(x, y, align='center') + ax.set_xticks(x) + ax.set_xticklabels(sorted(freqs, key=sort_key)) + f.show() + +if __name__ == "__main__": + import doctest + doctest.testmod()