安装模块
svgwrite
导入模块
import svgwrite
绘制一条直线并保存为svg文件
dwg=svgwrite.Drawing("test.svg", profile="full", width = 400,height=400)
dwg.add(dwg.line(start=(100, 100), end=(200, 100), stroke="red",stroke_width=3))
dwg.save()
其他
import svgwrite
#线条
dwg=svgwrite.Drawing("test.svg", profile="full", width = 400,height=400)
dwg.add(dwg.line(start=(100, 100), end=(200, 100), stroke="red",stroke_width=3))
dwg.save()
#矩形
dwg.add(dwg.rect(insert=(100,110),size=(100,100),rx =15,ry=15,fill="red",stroke="black", stroke_width=3))
#圆形
dwg.add(dwg.circle(center=(150,160),r=50, fill="blue",stroke="black"))
#椭圆
dwg.add(dwg.ellipse(center=(150,160),r=(60,30), fill="green",stroke="black"))
#多线条
dwg.add(dwg.polyline(points=[(100,50),(130,90),(160,50),(200,90)],fill="none",stroke="green",stroke_width=4))
#多边形
dwg.add(dwg.polygon(points=[(70,15),(75.8,32.2),(93.8,32.2),(79.4,43),(84.6,60.2),(70,50),(55.4,60.2),(60.6,43),(46.2,32.2),(64.2,32.2)],fill="red",stroke="blue"))
#文本
dwg.add(dwg.text("Test", insert=(10, 150), fill="red", font_family="Arial",font_size=32))