diff --git a/README.md b/README.md index de175c7..7c7e4cd 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ When drawing tasks, arckit will intelligently resize all of the grids such that ```python >>> task = vis.draw_task(train_set[0], width=10, height=6, label='Example') ->>> vis.output_drawing(grid, "images/arcshow_example.png") # svg/pdf/png +>>> vis.output_drawing(task, "images/arcshow_example.png") # svg/pdf/png ``` ![Example of arckit output](./images/arcsave_example.png) diff --git a/arckit/vis.py b/arckit/vis.py index 1c3d622..c4435b8 100644 --- a/arckit/vis.py +++ b/arckit/vis.py @@ -16,6 +16,8 @@ '#FFFFFF' ] +bg_color = '#EEEFF6' # White + def draw_grid(grid, xmax=10, ymax=10, padding=.5, extra_bottom_padding=0.5, group=False, add_size=True, label='', bordercol='#111111ff'): """ Draws a grid, @@ -65,6 +67,12 @@ def draw_grid(grid, xmax=10, ymax=10, padding=.5, extra_bottom_padding=0.5, grou drawing = drawsvg.Group() else: drawing = drawsvg.Drawing(xsize+padding, ysize+padding+extra_bottom_padding, origin=(-0.5*padding, -0.5*padding)) + # Add background rectangle first + drawing.append(drawsvg.Rectangle( + -0.5*padding, -0.5*padding, # x, y position with extra padding + xsize+padding, ysize+padding+extra_bottom_padding, # width, height with padding + fill=bg_color # background color `bg_color` + )) drawing.set_pixel_scale(40) # drawing = drawsvg.Group() for j, row in enumerate(grid): @@ -262,4 +270,4 @@ def output_drawing(d: drawsvg.Drawing, filename: str, context=None): import cairosvg cairosvg.svg2pdf(bytestring=buffer.getvalue(), write_to=filename) else: - raise ValueError(f'Unknown file extension for {filename}') \ No newline at end of file + raise ValueError(f'Unknown file extension for {filename}')