def graph_img(x, y, name): def y_precise(): result = ["chd=t:"] for elem in y: result.append(str(elem)) result.append(',') result[-1] = '&' return ''.join(result) G = Line(y, encoding='text') G.axes.type('xy') min_y = min(y) max_y = max(y) G.axes.range(1, min_y, max_y) G.scale(min_y, max_y) G.axes.label(0, x[0], x[-1]) G.axes.label(1, min_y, max_y) G.title(name) image_code = G.img() norm_img = re.sub(r'chd=t.*?\&', y_precise(), image_code) if len(norm_img) > 2000: if len(image_code) > 2000: raise LongPeriodException() else: return image_code return norm_img