-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlegend_example.py
More file actions
153 lines (112 loc) · 3.77 KB
/
legend_example.py
File metadata and controls
153 lines (112 loc) · 3.77 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# coding: utf-8
# In[1]:
get_ipython().run_line_magic('matplotlib', 'inline')
# In[17]:
import numpy as np
import matplotlib as mpl
# mpl.use('Agg')
from matplotlib import pyplot as plt
from viz_helpers import COLOR_BLUE, COLOR_WHITE, COLOR_YELLOW, COLOR_ORANGE, COLOR_GREEN, COLOR_PINK
# In[26]:
def plot_cbar(labels, output, ticks=[0, 1]):
plt.style.use('paper')
a = np.array([[0,1]])
fig = plt.figure(figsize=(9, 1.5))
img = plt.imshow(a, cmap="Reds")
plt.gca().set_visible(False)
cax = plt.axes([0.11, 0.3, 0.8, 0.2])
cbar = plt.colorbar(orientation="horizontal", cax=cax, ticks=ticks)
cbar.ax.set_xticklabels(labels)
cbar.outline.set_visible(False)
plt.tick_params(axis='both', which='major', labelsize=18)
# plt.tight_layout()
plt.savefig(o)
# In[27]:
inputs = [(['queried early', 'queried late'], 'figs/inspect-query-process/cbar.pdf'),
(['P(infected)=0', 'P(infected)=1'], 'figs/intro/cbar.pdf')]
for labels, o in inputs:
plot_cbar(labels, o)
# In[23]:
plt.style.use('paper')
import matplotlib.pyplot as plt
def plot_query_legend(output):
appearance_configs = [
(COLOR_BLUE, 's', 20), (COLOR_YELLOW, 'o', 20), (COLOR_ORANGE, '^', 20),
(COLOR_GREEN, 'p', 20), (COLOR_WHITE, 'o', 10)
]
labels = ['observed infected', 'hidden infected', 'query', 'source', 'hidden uninfected']
handles = []
for config in appearance_configs:
color, shape, size = config
h = plt.plot([],[],marker=shape, color=color,
markersize=size,
ls="none")[0]
handles.append(h)
legend = plt.legend(handles, labels, loc=2,
framealpha=1, frameon=False,
ncol=3,
numpoints=1)
plt.axis('off')
fig = legend.figure
fig.canvas.draw()
bbox = legend.get_window_extent().transformed(fig.dpi_scale_trans.inverted())
fig.savefig(output, dpi="figure", bbox_inches=bbox)
# plt.show()
# In[24]:
outputs = ['figs/inspect-query-process/legend.pdf',
'figs/intro/legend.pdf']
for o in outputs:
plot_query_legend(o)
# In[32]:
plt.style.use('paper')
ax = plt.subplot()
method_configs = [
(COLOR_ORANGE, 'o', '-'),
(COLOR_PINK, '*', ':'),
(COLOR_BLUE, '^', '--'),
(COLOR_GREEN, 'v', '-.'),
(COLOR_YELLOW, 's', '-')
]
labels = ['random', 'pagerank', 'entropy', 'cond-entropy', 'mutual-info']
size = 32
handles = []
for config in method_configs:
color, shape, linestyle = config
h = ax.plot([],[], marker=shape, color=color,
linestyle=linestyle,
markersize=size)[0]
handles.append(h)
legend = ax.legend(handles, labels, loc=2,
framealpha=1, frameon=False,
fontsize=32,
ncol=5)
ax.axis('off')
fig = legend.figure
fig.canvas.draw()
bbox = legend.get_window_extent().transformed(fig.dpi_scale_trans.inverted())
fig.savefig('figs/method_legend.pdf', dpi="figure", bbox_inches=bbox)
# In[31]:
plt.style.use('paper')
ax = plt.subplot()
method_configs = [
(COLOR_ORANGE, '^', ':'),
(COLOR_BLUE, 'v', '--'),
]
labels = ['SI', 'community']
size = 32
handles = []
for config in method_configs:
color, shape, linestyle = config
h = ax.plot([],[], marker=shape, color=color,
linestyle=linestyle,
markersize=size)[0]
handles.append(h)
legend = ax.legend(handles, labels, loc=2,
framealpha=1, frameon=False,
fontsize=32,
ncol=5)
ax.axis('off')
fig = legend.figure
fig.canvas.draw()
bbox = legend.get_window_extent().transformed(fig.dpi_scale_trans.inverted())
fig.savefig('figs/cascade_legend.pdf', dpi="figure", bbox_inches=bbox)