Generate sample browser usage stats

from PIL import Image, ImageDraw, ImageFont # Use your own fonts here free_sans = ImageFont.truetype('/path/to/font_dir/FreeSansBold.ttf', 22) fira_medium = ImageFont.truetype('/path/to/font_dir/FiraSans-Medium.otf', 14) fira_light = ImageFont.truetype('/path/to/font_dir/FiraSans-Light.otf', 14) # Data to plot on the pie chart browser_usage_data = [ ('Chrome', 45), ('Firefox', 28), ('IE/Edge', 17), ('Opera', 7), ('Safari', 3) ] sum_data = sum(v for _, v in browser_usage_data) title = "Browser usage stats" imx, imy = 640, 380 background_color = (255,255,255) font_color = (0,0,0,0) black, grey = '#000000', '#777777' colors = ['#97F3FF', '#71E8E1', '#A4FFE9', '#59E8AC', '#94FFBF'] im = Image.new("RGBA", (imx, imy), background_color) draw = ImageDraw.Draw(im) # Draw chart title draw.text((250,30), title, font=free_sans, fill=font_color) start_angle = -90 # starts drawing the pie chart at 0 o'clock rect_x, rect_y = 400, 110 rect_side = 28 for i, (browser, share) in enumerate(browser_usage_data): percentage_factor = share / sum_data percentage = round(percentage_factor*100) percentage = (' ' if percentage < 10 else '') + str(percentage) + ' %' fill_color = colors[i] # Top-left and bottom-right points, angles in degrees draw.pieslice([(60,80),(300,320)], start_angle, start_angle + percentage_factor*360, fill_color, black) draw.rectangle([(rect_x, rect_y), (rect_x+1.5*rect_side, rect_y+rect_side)], fill_color, black) draw.text((rect_x+rect_side/4, rect_y+rect_side/4-1), percentage, font=fira_medium, fill=grey) draw.text((rect_x+1.5*rect_side+0.3*rect_side, rect_y+rect_side/4-1), browser, font=fira_light, fill=black) rect_y += 1.3*rect_side start_angle += percentage_factor*360 im.show()

Executing this code creates the following image:

Every time when the data changes, we can re-run the code to update this image without having to draw anything by hand.