-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_html.py
119 lines (107 loc) · 3.1 KB
/
make_html.py
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 20 18:00:58 2017
@author: ryuhei
"""
import os
import itertools
from glob import glob
from string import Template
import numpy as np
def make_html(images_dir_path='.'):
html_template_str = '''
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="https://code.highcharts.com/highcharts.js"></script>
<script type="text/javascript" src="https://code.highcharts.com/modules/exporting.js"></script>
</head>
<body>
<div id="container"></div>
<script>
$(function () {
Highcharts.chart('container', {
chart: {
type: 'scatter',
width: 50000,
height: 2000,
zoomType: 'x',
panning: true,
panKey: 'shift',
spacingBottom: 0
},
title: {
text: 'Title'
},
xAxis: {
title: {
enabled: true,
text: 'Error in logarithm of aspect ratio (error = truth - estimation, which means the more positive the wider)'
},
startOnTick: true,
endOnTick: true,
showLastLabel: true,
tickInterval: 0.01,
},
yAxis: {
minorGridLineWidth: 0
},
plotOptions: {
scatter: {
marker: {
radius: 5,
states: {
hover: {
enabled: true,
lineColor: 'rgb(100,100,100)'
}
}
},
states: {
hover: {
marker: {
enabled: false
}
}
},
tooltip: {
headerFormat: '',
pointFormat: '{point.x}'
}
}
},
series: [{
name: 'Images',
data: [${data}]
}]
});
});
</script>
</body>
</html>
'''
glob_expr = os.path.join(images_dir_path, '*.png')
data = []
y_iter = itertools.cycle(range(200, 2000, 237))
for filepath in glob(glob_expr):
basename = os.path.basename(filepath)
x = os.path.splitext(basename)[0]
# y = np.random.uniform(-1000, 1000)
y = next(y_iter)
datum_template = Template('''
{x: $x,
y: $y,
marker: {
symbol: 'url(./$file_name)'
}}''')
datum = datum_template.substitute(x=x, y=y, file_name=basename)
data.append(datum)
data_str = ",\n".join(data)
html_template = Template(html_template_str)
html_str = html_template.safe_substitute(data=data_str)
output_file_path = os.path.join(images_dir_path, 'index.html')
with open(output_file_path, 'w') as f:
f.write(html_str)
if __name__ == '__main__':
images_dir_path = '.' # 画像が配置されているフォルダのパスを指定する
make_html(images_dir_path)