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.
Lay out Toyplot legends horizontally
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])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment