import math def create_bar(image_width, image_height, times): image_code = [''] colors = ["00193dff", "05597fff", "54babfff", "bfe3c2ff", "ffbf6bff", "fdb55cff", "f37f73ff", "7f3d85ff", "4a217aff", "00193dff"] for i in range(0, 10): start_point = (((100 / 1440) * times[i] / 100) * image_width) width = math.ceil((((100 / 1440) * (times[i + 1] - times[i]) / 100) * image_width)) image_code.append('' % (colors[i], start_point, width)) bar_part_mid = start_point + width / 2 if (i < 5): polyline_x = i * 10 + 10 polyline_y = 0 image_x = 100 + i * (200 + 8) elif (i < 9): polyline_x = (i - 4) * 10 + 160 polyline_y = 210 image_x = 200 + (i - 5) * (200 + 8) if i < 9: image_code.append( '' % (image_x, polyline_y, image_x, polyline_x, bar_part_mid, polyline_x, bar_part_mid, colors[i]) ) for i in range(0, 8): image_code.append( '' % (i * (image_width // 8), i * (image_width // 8)) ) image_code.append( '%s' % (i * (image_width // 8) + 5, i * 3) ) # Write to file file = open("time_bar.svg", "w") for i in image_code: file.write(i + '\n') file.write('')