Skip to content

Instantly share code, notes, and snippets.

@johanndt
Created October 21, 2016 00:26
Show Gist options
  • Save johanndt/01c9fa64a3e889abb336cff1ccbbacfb to your computer and use it in GitHub Desktop.
Save johanndt/01c9fa64a3e889abb336cff1ccbbacfb to your computer and use it in GitHub Desktop.

Revisions

  1. johanndt created this gist Oct 21, 2016.
    16 changes: 16 additions & 0 deletions horizontal_legend.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    from PIL import ImageFont
    import toyplot

    series_names = ["Series 1", "Series 2", "Series 3"]
    canvas = toyplot.Canvas(width=300, height=300)

    font = ImageFont.load_default()
    next_x = 0
    for legend in series_names:
    canvas.legend([
    (legend, {"shape": "s", "mstyle":{"fill":"green", "stroke": "none"}})
    ],
    rect=(next_x, 0, 200, 30))

    # some trial and error was used to scale this right
    next_x = next_x + 30 + (1.2 * font.getsize(legend)[0])