Skip to content

Commit

Permalink
Minor changes to plotted figures
Browse files Browse the repository at this point in the history
  • Loading branch information
rhjohnstone committed Jan 10, 2017
1 parent ab98e7b commit e348229
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
53 changes: 52 additions & 1 deletion python/PyHillFit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import argparse
import scipy.stats as st
import matplotlib.patches as mpatches

try:
import cma
Expand Down Expand Up @@ -346,6 +347,9 @@ def run_hierarchical(drug_channel):
mins = [0,0,-5,0,0]
maxs = [8,22,20,2,25]

prior_xs = []
priors = []

total_axes = (6,4)
fig = plt.figure(figsize=(6,7))
for i in range(len(labels)-1):
Expand All @@ -360,6 +364,8 @@ def run_hierarchical(drug_channel):
ax = plt.subplot2grid(total_axes, axloc,colspan=2,rowspan=2)
x_prior = np.linspace(mins[i],maxs[i],501)
prior = st.gamma.pdf(x_prior,a=shapes[i],scale=scales[i],loc=locs[i])
prior_xs.append(x_prior)
priors.append(prior)
ax.plot(x_prior,prior,label='Gamma prior',lw=2)
ax.set_xlabel(labels[i])
ax.set_ylabel('Probability density')
Expand All @@ -375,7 +381,11 @@ def run_hierarchical(drug_channel):
i = len(labels)-1
ax = plt.subplot2grid(total_axes, (4,1),colspan=2,rowspan=2)
x_prior = np.linspace(mins[i],maxs[i],501)
ax.plot(x_prior,st.gamma.pdf(x_prior,a=shapes[i],scale=scales[i],loc=locs[i]),label='Gamma prior',lw=2)
prior = st.gamma.pdf(x_prior,a=shapes[i],scale=scales[i],loc=locs[i])
ax.plot(x_prior,prior,label='Gamma prior',lw=2)
prior_xs.append(x_prior)
priors.append(prior)

ax.set_xlabel(labels[i])
ax.set_ylabel('Probability density')
ax.set_xlim(mins[i],maxs[i])
Expand Down Expand Up @@ -559,6 +569,47 @@ def run_hierarchical(drug_channel):
#fig.savefig(marginals_dir+'{}_{}_{}_marginal.pdf'.format(drug,channel,filename))
plt.close()

total_axes = (6,4)
fig = plt.figure(figsize=(6,7))
for i in range(5): # have to do sigma separately
if i==0:
axloc = (0,0)
elif i==1:
axloc = (0,2)
elif i==2:
axloc = (2,0)
elif i==3:
axloc = (2,2)
elif i==4:
axloc = (4,0)
ax = plt.subplot2grid(total_axes, axloc,colspan=2,rowspan=2)

ax.set_xlabel(labels[i])
ax.set_ylabel('Probability density')

ax.grid()
if (i<4):
min_sample = np.min(chain[burn:,i])
max_sample = np.max(chain[burn:,i])
ax.hist(chain[burn:,i],bins=50,normed=True,color='blue',edgecolor='blue')
elif (i==4):
min_sample = np.min(chain[burn:,-2])
max_sample = np.max(chain[burn:,-2])
ax.hist(chain[burn:,-2],bins=50,normed=True,color='blue',edgecolor='blue') # -1 would be log-target
ax.set_xlim(min_sample,max_sample)
pts_in_this_range = np.where((prior_xs[i] >= min_sample) & (prior_xs[i] <= max_sample))
x_in_this_range = prior_xs[i][pts_in_this_range]
prior_in_this_range = priors[i][pts_in_this_range]
line = ax.plot(x_in_this_range,prior_in_this_range,lw=2,color='red',label='Prior distributions')
leg_ax = plt.subplot2grid(total_axes, (4,2),colspan=2,rowspan=2)
leg_ax.axis('off')
hist = mpatches.Patch(color='blue', label='Normalised histograms')
leg_ax.legend(handles=line+[hist],loc="center",fontsize=12,bbox_to_anchor=[0.38,0.7])
fig.tight_layout()
fig.savefig(figs_dir+'all_prior_distributions_and_marginals.png')
fig.savefig(figs_dir+'all_prior_distributions_and_marginals.pdf')
plt.close()

print "Marginal plots saved in", marginals_dir

print "\n\n{} + {} complete!\n\n".format(drug,channel)
Expand Down
10 changes: 5 additions & 5 deletions python/plot_all_predicted_curves.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def run(drug_channel):
ax1.set_xlim(10**xmin,10**xmax)

for expt in experiment_numbers:
ax1.scatter(experiments[expt][:,0],experiments[expt][:,1],label='Expt {}'.format(expt+1),color=colors[expt],s=100)
ax1.scatter(experiments[expt][:,0],experiments[expt][:,1],label='Expt {}'.format(expt+1),color=colors[expt],s=100,zorder=10)

for i, conc in enumerate(args.concs):
ax1.axvline(conc,color=colors[3+i],lw=2,label=r"{} $\mu$M".format(conc),alpha=0.8)
Expand Down Expand Up @@ -112,7 +112,7 @@ def run(drug_channel):
ax3.set_xlim(10**xmin,10**xmax)

for expt in experiment_numbers:
ax3.scatter(experiments[expt][:,0],experiments[expt][:,1],label='Expt {}'.format(expt+1),color=colors[expt],s=100)#,zorder=10)
ax3.scatter(experiments[expt][:,0],experiments[expt][:,1],label='Expt {}'.format(expt+1),color=colors[expt],s=100,zorder=10)

chain = np.loadtxt(chain_file)
end = chain.shape[0]
Expand Down Expand Up @@ -173,9 +173,9 @@ def run(drug_channel):

for expt in experiment_numbers:
if expt==1:
ax5.scatter(experiments[expt][:,0],experiments[expt][:,1],color='orange',s=100,label='All expts')
ax5.scatter(experiments[expt][:,0],experiments[expt][:,1],color='orange',s=100,label='All expts',zorder=10)
else:
ax5.scatter(experiments[expt][:,0],experiments[expt][:,1],color='orange',s=100)
ax5.scatter(experiments[expt][:,0],experiments[expt][:,1],color='orange',s=100,zorder=10)

for i, conc in enumerate(args.concs):
ax5.axvline(conc,color=colors[3+i],alpha=0.8,lw=2,label=r"{} $\mu$M".format(conc))
Expand Down Expand Up @@ -203,7 +203,7 @@ def run(drug_channel):

fig.tight_layout()
fig.savefig(plot_dir+'{}_{}_all_predictions.png'.format(drug,channel))
#fig.savefig(plot_dir+'{}_{}_all_predictions.pdf'.format(drug,channel)) # uncomment to save as pdf, or change extension to whatever you want
fig.savefig(plot_dir+'{}_{}_all_predictions.pdf'.format(drug,channel)) # uncomment to save as pdf, or change extension to whatever you want


plt.close()
Expand Down

0 comments on commit e348229

Please sign in to comment.