import math import matplotlib.pyplot as plt from util.debug import DEBUG from util.debug import debug_print def up_down_list(_list): min_value = min(_list) max_value = max(_list) return [-(x - min_value) + max_value for x in _list] def min_max_list(src_list, tar_min, tar_max): src_min = min(src_list) src_max = max(src_list) src_range = abs(src_max - src_min) tar_range = abs(tar_max - tar_min) scale_ratio = 0 if src_range == 0 else tar_range / src_range floor_up = [v - src_min for v in src_list] scale_to = [v * scale_ratio for v in floor_up] floor_down = [v + tar_min for v in scale_to] return floor_down def draw_lists(title='', date_list=None, **kv_list): debug_print('draw_lists, date_list = ', str(date_list)) idx_list = 0 idx_axs = 0 rows = math.ceil(len(kv_list.items()) / 3) fig, axs = plt.subplots(rows, 1, sharex=True) for key, value in kv_list.items(): if type(key) is str and type(value) is list: axs[idx_axs].plot(date_list, value, label=key) axs[idx_axs].legend() idx_list = idx_list + 1 idx_axs = int(idx_list / 3) plt.gcf().autofmt_xdate() # plt.title(title) if DEBUG: # plt.show() file_uri = '.doc/' + title + '.png' fig.savefig(file_uri) else: file_uri = '.doc/' + title + '.png' fig.savefig(file_uri) return fig