File size: 1,762 Bytes
5dedebd
f1f2090
28cc8f4
5dedebd
28cc8f4
6b4e7c6
9492e32
5dedebd
f1f2090
6b4e7c6
1d5a710
 
 
 
 
 
 
 
 
 
 
5dedebd
1d5a710
 
 
 
eb8dea9
 
5dedebd
9492e32
5dedebd
 
 
 
 
 
 
 
 
 
 
f13c4bb
28cc8f4
 
 
 
 
9492e32
2e905cb
9492e32
 
 
 
 
eb8dea9
 
5dedebd
9492e32
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import math

import dateutil.tz
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

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)

    # tz = dateutil.tz.gettz('Asia/Shanghai')
    # # date_format = date_list.DateFormatter('%d-%m-%Y')
    # plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%b/%d %H:%M', tz=tz))
    # # plt.gca().xaxis.set_major_formatter(date_format)
    # plt.xticks(rotation=25)
    plt.gcf().autofmt_xdate()
    axs[0].set_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