import matplotlib.pyplot as plt import debug from debug import debug_print def draw(x_points=None, y_points=None): plt.plot(x_points) plt.ylim(ymin=0, ymax=120) plt.show() def draw_two(title='', x_list1=None, x_list2=None): fig, ax = plt.subplots() ax.plot(x_list1) ax.plot(x_list2) ax.legend() plt.ylim(ymin=0, ymax=120) plt.title(title) plt.show() 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 = 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_three(title='', date_list=None, x_list1=None, x_list2=None, x_list3=None, light_list=None, screen_list=None): debug_print('draw_three, date_list = ', str(date_list)) debug_print('draw_three, light_list = ', str(light_list)) if screen_list is not None: screen_list = [(x - 2) * 4 for x in screen_list] screen_list = up_down_list(screen_list) # screen_list = map(lambda x: (x - 2) * 4, screen_list) if light_list is not None: light_list2 = min_max_list(light_list, -20, -10) fig, axs = plt.subplots(2, 1, sharex=True) # axs[0].axes.get_xaxis().set_visible(False) if date_list is None: axs[0].plot(x_list1, label='max', color='blue') axs[0].plot(x_list2, label='min', color='orange') axs[0].plot(x_list3, label='acc', color='green') axs[1].plot(screen_list, label='screen') axs[1].plot(light_list, label='light') else: axs[0].plot(date_list, x_list1, label='max', color='blue') axs[0].plot(date_list, x_list2, label='min', color='orange') axs[0].plot(date_list, x_list3, label='acc', color='green') axs[1].plot(date_list, screen_list, label='screen') axs[1].plot(date_list, light_list, label='light') plt.gcf().autofmt_xdate() # plt.ylim(ymin=-30, ymax=20000) # plt.title(title) if debug.DEBUG: plt.show() else: file_uri = '.doc/' + title + '.png' plt.savefig(file_uri)