thelou1s commited on
Commit
1d5a710
1 Parent(s): eb8dea9

draw axs[0], axs[1]

Browse files
Files changed (1) hide show
  1. draw_db.py +35 -19
draw_db.py CHANGED
@@ -22,38 +22,54 @@ def draw_two(title='', x_list1=None, x_list2=None):
22
  plt.show()
23
 
24
 
25
- def up_down_list(list):
26
- min_value = min(list)
27
- max_value = max(list)
28
- return [-(x - min_value) + max_value for x in list]
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
 
31
  def draw_three(title='', date_list=None, x_list1=None, x_list2=None, x_list3=None, light_list=None, screen_list=None):
32
  debug_print('draw_three, date_list = ', str(date_list))
 
33
 
34
  if screen_list is not None:
35
  screen_list = [(x - 2) * 4 for x in screen_list]
36
  screen_list = up_down_list(screen_list)
37
  # screen_list = map(lambda x: (x - 2) * 4, screen_list)
38
 
39
- fig, ax = plt.subplots()
 
 
 
 
40
  if date_list is None:
41
- ax.plot(screen_list, label='screen', color='darkgrey')
42
- ax.plot(light_list, label='light', color='lightgrey')
43
- ax.plot(x_list1, label='max', color='blue')
44
- ax.plot(x_list2, label='min', color='orange')
45
- ax.plot(x_list3, label='acc', color='green')
46
  else:
47
- ax.plot(date_list, screen_list, label='screen', color='darkgrey')
48
- ax.plot(date_list, light_list, label='light', color='lightgrey')
49
- ax.plot(date_list, x_list1, label='max', color='blue')
50
- ax.plot(date_list, x_list2, label='min', color='orange')
51
- ax.plot(date_list, x_list3, label='acc', color='green')
52
- ax.legend()
53
- plt.gcf().autofmt_xdate()
54
 
55
- plt.ylim(ymin=-10, ymax=130)
56
- plt.title(title)
 
57
 
58
  if debug.DEBUG:
59
  plt.show()
 
22
  plt.show()
23
 
24
 
25
+ def up_down_list(_list):
26
+ min_value = min(_list)
27
+ max_value = max(_list)
28
+ return [-(x - min_value) + max_value for x in _list]
29
+
30
+
31
+ def min_max_list(src_list, tar_min, tar_max):
32
+ src_min = min(src_list)
33
+ src_max = max(src_list)
34
+ src_range = abs(src_max - src_min)
35
+ tar_range = abs(tar_max - tar_min)
36
+ scale_ratio = tar_range / src_range
37
+ floor_up = [v - src_min for v in src_list]
38
+ scale_to = [v * scale_ratio for v in floor_up]
39
+ floor_down = [v + tar_min for v in scale_to]
40
+ return floor_down
41
 
42
 
43
  def draw_three(title='', date_list=None, x_list1=None, x_list2=None, x_list3=None, light_list=None, screen_list=None):
44
  debug_print('draw_three, date_list = ', str(date_list))
45
+ debug_print('draw_three, light_list = ', str(light_list))
46
 
47
  if screen_list is not None:
48
  screen_list = [(x - 2) * 4 for x in screen_list]
49
  screen_list = up_down_list(screen_list)
50
  # screen_list = map(lambda x: (x - 2) * 4, screen_list)
51
 
52
+ if light_list is not None:
53
+ light_list2 = min_max_list(light_list, -20, -10)
54
+
55
+ fig, axs = plt.subplots(2, 1, sharex=True)
56
+ # axs[0].axes.get_xaxis().set_visible(False)
57
  if date_list is None:
58
+ axs[0].plot(x_list1, label='max', color='blue')
59
+ axs[0].plot(x_list2, label='min', color='orange')
60
+ axs[0].plot(x_list3, label='acc', color='green')
61
+ axs[1].plot(screen_list, label='screen')
62
+ axs[1].plot(light_list, label='light')
63
  else:
64
+ axs[0].plot(date_list, x_list1, label='max', color='blue')
65
+ axs[0].plot(date_list, x_list2, label='min', color='orange')
66
+ axs[0].plot(date_list, x_list3, label='acc', color='green')
67
+ axs[1].plot(date_list, screen_list, label='screen')
68
+ axs[1].plot(date_list, light_list, label='light')
 
 
69
 
70
+ plt.gcf().autofmt_xdate()
71
+ # plt.ylim(ymin=-30, ymax=20000)
72
+ # plt.title(title)
73
 
74
  if debug.DEBUG:
75
  plt.show()