3from __future__
import division
8__all__=(
'make_disk_plot',)
11 from matplotlib
import pyplot
as plt
12 from matplotlib
import rc
13 rc(
'text', usetex=
False)
14 rc(
'font', family=
'lmodern')
17 rc(
'axes', labelsize=big)
19 rc(
'legend', fontsize=small)
20 rc(
'xtick', labelsize=small)
21 rc(
'ytick', labelsize=small)
27 print(
"cannot import corner. Won't plot spin disk")
37 if not set([a1,a2,tilt1,tilt2]).issubset(names):
38 print(
"Cannot plot spin disk plot. Not all required spin parameters exist in the posterior file. Skipping...\n")
42 fig, axs = plt.subplots(1, 2, sharey=
True, figsize=(4, 4))
45 xticks = [0., .25, .5, .75, 1.]
49 for a, tilt
in zip([a1, a2], [tilt1, tilt2]):
50 asamps=(post[a].samples).flatten()
51 tsamps=(post[tilt].samples).flatten()
53 H, _, _ = np.histogram2d(asamps, np.cos(tsamps), range=[[0, 1], [-1, 1]], bins=(Na, Nt), density=
True)
56 H, _, _ = np.histogram2d(asamps, np.cos(tsamps), range=[[0, 1], [-1, 1]], bins=(Na, Nt), normed=
True)
57 vmax = H.max()
if H.max() > vmax
else vmax
60 for ax, a, tilt, flip
in zip(axs, [a1, a2], [tilt1, tilt2], [
True,
False]):
61 asamps=(post[a].samples).flatten()
62 tsamps=(post[tilt].samples).flatten()
65 H, rs, costs = np.histogram2d(asamps, np.cos(tsamps), range=[[0, 1], [-1, 1]], bins=(Na, Nt), density=
True)
68 H, rs, costs = np.histogram2d(asamps, np.cos(tsamps), range=[[0, 1], [-1, 1]], bins=(Na, Nt), normed=
True)
70 COSTS, RS = np.meshgrid(costs, rs)
71 X = RS * np.sin(np.arccos(COSTS))
74 HS = np.column_stack((X.flatten(), Y.flatten()))
75 XS = np.reshape(HS[:,0], (Na+1,Nt+1))
76 YS = np.reshape(HS[:,1], (Na+1,Nt+1))
78 plt.pcolormesh(XS, YS, H, vmin=vmin, vmax=vmax, edgecolor=
'face', cmap=
'Greys')
80 ax.set_ylim((-1., 1.))
83 ax.set_xticks(xticks[1:])
88 ax.yaxis.set_label_position(
"right")
90 axs[0].set_xlabel(
r'$|\mathbf{S_1} \times \mathbf{\hat{L}}|$')
91 axs[1].set_xlabel(
r'$|\mathbf{S_2} \times \mathbf{\hat{L}}|$')
92 axs[0].set_ylabel(
r'$\mathbf{S_1}\cdot\mathbf{\hat{L}}$')
93 axs[1].set_ylabel(
r'$\mathbf{S_2}\cdot\mathbf{\hat{L}}$')
95 fig.subplots_adjust(wspace=0.04)
96 cax = fig.add_axes([0.06, -0.075, 0.9, 0.05])
98 cbar = plt.colorbar(orientation=
'horizontal', cax=cax)
99 cbar.formatter.set_powerlimits((-1, 1))
101 cbar.set_label(
'posterior probability')
102 cbar.solids.set_edgecolor(
"face")
103 plt.savefig(os.path.join(outpath,
"comp_spin_pos.png"), bbox_inches=
'tight')
def make_disk_plot(post, outpath=None)