pip install genshi python import genshi import genshi.builder as gbuilder import numpy as np python python rect = gbuilder.create("rect") python with open("output.svg", "w") as f: python python import genshi import genshi.builder as gbuilder import numpy as np students = ['Alice', 'Bob', 'Charlie', 'David', 'Eve'] x = np.arange(len(students)) bar_width = 20 bar_spacing = 10 bars = [] for i, student in enumerate(students): bar = gbuilder.create("rect") bar.attribs.update( x=(i * (bar_width + bar_spacing)) + 50, y=svg.height - scores[i] - 50, width=bar_width, height=scores[i], fill="blue" ) bars.append(bar) legend = gbuilder.create("g") legend.attribs.update(font_size="12") for i, student in enumerate(students): text = gbuilder.create("text") text.attribs.update( x=(i * (bar_width + bar_spacing)) + 50, y=svg.height - 30, text_anchor="middle" ) text.append(student) legend.append(text) svg.extend(bars) svg.append(legend) with open("output.svg", "w") as f: f.write(svg.render().encode("utf-8"))


上一篇:
下一篇:
切换中文