import cairo surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 100, 100) ctx = cairo.Context(surface) ctx.scale(10, 10) ctx.set_source_rgb(255, 0, 0) ctx.move_to(0, 5) ctx.line_to(10, 5) ctx.set_dash([1], 1) ctx.set_line_width(1) ctx.stroke() surface.write_to_png(open('test.png', 'w'))