|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | import sys, argparse |
| 3 | +import matplotlib |
| 4 | +rc_params = {'text.usetex': True, |
| 5 | + 'svg.fonttype': 'none', |
| 6 | + 'text.latex.preamble': r'\usepackage{libertine}', |
| 7 | + 'font.size': 14, |
| 8 | + 'font.family': 'Linux Libertine', |
| 9 | + 'mathtext.fontset': 'custom', |
| 10 | + 'mathtext.rm': 'libertine', |
| 11 | + 'mathtext.it': 'libertine:italic', |
| 12 | + 'mathtext.bf': 'libertine:bold' |
| 13 | + } |
| 14 | +matplotlib.rcParams.update(rc_params) |
3 | 15 | import matplotlib.pyplot as plt |
4 | 16 | import json |
5 | 17 | from pprint import pprint |
6 | 18 |
|
| 19 | + |
7 | 20 | def errorexit(msg='internal error', code=1): |
8 | 21 | print(msg, file=sys.stderr) |
9 | 22 | sys.exit(code) |
@@ -42,25 +55,36 @@ def errorexit(msg='internal error', code=1): |
42 | 55 | activity_to_color = {activity: colors[i] for i, activity in enumerate(activity_names)} |
43 | 56 |
|
44 | 57 | # Creating the joint plot |
45 | | -scaling = .9 |
| 58 | +scaling = 6 |
46 | 59 | iymax = (len(data)+1)//2 |
47 | | -fig = plt.figure(figsize=(scaling*16, scaling*9/2*iymax)) |
| 60 | +fig = plt.figure(figsize=(scaling, scaling/2*iymax)) |
48 | 61 |
|
49 | 62 | i = 1 |
| 63 | +inst_names = {} |
50 | 64 | for inst, idata in data.items(): |
51 | 65 | ax = fig.add_subplot(iymax, min(2, len(data)), i) |
52 | | - ax.pie(idata['activity_weights'], colors=colors, startangle=140, shadow=True, radius=.8) |
| 66 | + ax.pie(idata['activity_weights'], colors=colors, startangle=90, shadow=True, radius=1) |
53 | 67 | inst_name = idata['institution_name'] |
54 | 68 | if 'group_name' in idata: |
55 | | - inst_name = idata['group_name'] + "\n" + inst_name |
| 69 | + inst_name = idata['group_name'] + ", " + inst_name |
56 | 70 | if not args['hide_titles']: |
57 | | - ax.set_title(inst_name, fontsize=20, y=-0.05) |
| 71 | + ax.set_title(chr(ord('a')-1+i), y=-0.05) |
| 72 | + inst_names[chr(ord('a')-1+i)] = inst_name |
58 | 73 | i += 1 |
59 | 74 |
|
60 | 75 | # Shared legend |
61 | 76 | if args['legend']: |
62 | | - fig.legend(activity_names, title="Activities", loc="center right", bbox_to_anchor=(1.2, 0.5), fontsize=20) |
| 77 | + legend = fig.legend(activity_names, title="Activities", |
| 78 | + loc="upper right", bbox_to_anchor=(1.4, .7), frameon=False) |
| 79 | + #nothing = matplotlib.patches.Rectangle((0,0), 1, 1, fill=False, edgecolor='none', visible=False) |
| 80 | + #legend_inst = plt.legend([nothing]*len(inst_names), |
| 81 | + # [i+": "+inst_name for i, inst_name in inst_names.items()], |
| 82 | + # loc="upper left", bbox_to_anchor=(-1.2, 0.0), frameon=False) |
| 83 | + #plt.gca().add_artist(legend_inst) |
| 84 | + with open(args['outfile'].replace('.pdf', '.labels'), 'w') as f: |
| 85 | + f.write(', '.join([i+": "+inst_name for i, inst_name in inst_names.items()])) |
63 | 86 |
|
64 | 87 | plt.tight_layout() |
| 88 | +fig.subplots_adjust(bottom=0) |
65 | 89 | fig.savefig(args['outfile'], bbox_inches='tight') |
66 | 90 | # plt.show() |
0 commit comments