ソース
# -*- coding:utf-8 -*- import hashlib import re import itertools import numpy as np import matplotlib.pyplot as plt # グラフ化する文字列の数 UNIT_OF_SECTION = 5 def trans_to_nums(s): s = s.encode('UTF-8') m = hashlib.md5() m.update(s) h = m.hexdigest() # hは16進数32桁 # 4桁づつ、リストにする。 # https://stackoverflow.com/questions/13673060/split-string-into-strings-by-length nums = [ int(i, 16) for i in re.split('(.{4})', h)[1::2] ] return nums def get_strings(): strings = [ 'hoge1', 'hoge2', 'hoge3', 'hoge4', 'hoge5', 'fuga1', 'fuga2', 'fuga3', 'fuga4', 'piyo1', 'piyo2', 'piyo3' ] return strings def get_data(): all_strings = get_strings() all_strings = itertools.zip_longest(*[iter(all_strings)]*UNIT_OF_SECTION) data = list() for section_strings in all_strings: section_data = list() for s in section_strings: if s: section_data.extend(trans_to_nums(s)) data.append(section_data) return data def output_graph(data): # https://stackoverflow.com/questions/24943991/change-grid-interval-and-specify-tick-labels-in-matplotlib for d in data: x, y = (range(len(d)), d) fig, ax = plt.subplots() major_xticks = np.arange(0, UNIT_OF_SECTION*8+1, 8) minor_xticks = np.arange(0, UNIT_OF_SECTION*8+1, 1) major_yticks = np.arange(0, 65535+1, (65535+1)/5) minor_yticks = np.arange(0, 65535+1, (65535+1)/5/5) ax.set_xticks(major_xticks) ax.set_xticks(minor_xticks, minor=True) ax.set_yticks(major_yticks) ax.set_yticks(minor_yticks, minor=True) ax.grid(which='both') ax.grid(which='minor', alpha=0.2) ax.grid(which='major', alpha=0.8) plt.plot(x, y) plt.xlim([0, UNIT_OF_SECTION*8]) plt.ylim([0, 65535]) plt.show() def main(): data = get_data() output_graph(data) main()
アウトプット
1〜5個目までの文字列の画像化
6〜10個目までの文字列の画像化
11〜13個目までの文字列の画像化