Created
October 21, 2016 00:26
-
-
Save johanndt/01c9fa64a3e889abb336cff1ccbbacfb to your computer and use it in GitHub Desktop.
Lay out Toyplot legends horizontally
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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