-
Notifications
You must be signed in to change notification settings - Fork 72
/
viz_template.py
69 lines (59 loc) · 1.75 KB
/
viz_template.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
TITLE & DESCRIPTION
Author: Aaron Penne
Created: YYYY-MM-DD
Developed with:
Python 3.6
macOS 10.13
"""
import os
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams['font.family'] = 'monospace'
###############################################################################
# Set up directories
code_dir = os.path.dirname(__file__)
data_dir = os.path.join(code_dir, 'data')
output_dir = os.path.join(code_dir, 'output')
if not os.path.isdir(output_dir):
os.mkdir(output_dir)
###############################################################################
# Wrangle and process data
# Get input data
input_file = os.path.join(data_dir, 'FILENAME.csv')
df = pd.read_csv(input_file)
###############################################################################
# Create visualization
fig, ax = plt.subplots(figsize=(4, 6), dpi=200)
# Title and annotations
ax[0].text(center, 7.5,
'Religion of Nobel Prize Winners 1901-2000',
va='bottom',
ha='center',
color=color,
size='small',
multialignment = 'center')
ax[0].text(0, 6.7,
'Global Population',
fontdict=fontdict,
ha='right')
ax[1].text(0, 6.7,
'Nobel Prize Winners',
fontdict=fontdict,
ha='left')
ax[1].text(center, -1.3,
'Data: "100 Years of Nobel Prizes" & Wikipedia\n' \
'Code: www.github.com/aaronpenne\n' \
'@aaronpenne © 2018',
fontdict=fontdict,
va='top',
ha='center',
multialignment = 'center')
fig.savefig(os.path.join(output_dir, 'FILE.png'),
dpi=fig.dpi,
bbox_inches='tight',
pad_inches=0.3)
plt.close(fig)