def allplot(xb,yb,bins=30,fig=1,xlabel='x',ylabel='y'):
"""
Input:
X,Y : objects referring to the variables produced by PyMC that you want
to analyze. Example: X=M.theta, Y=M.slope.
Inherited from Tommy LE BLANC's code at astroplotlib|STSCI.
"""
#X,Y=xb.trace(),yb.trace()
X,Y=xb,yb
#pylab.rcParams.update({'font.size': fontsize})
fig=pylab.figure(fig)
pylab.clf()
gs = pylab.GridSpec(2, 2, width_ratios=[3,1], height_ratios=[1,3], wspace=0.07, hspace=0.07)
scat=pylab.subplot(gs[2])
histx=pylab.subplot(gs[0], sharex=scat)
histy=pylab.subplot(gs[3], sharey=scat)
#scat=fig.add_subplot(2,2,3)
#histx=fig.add_subplot(2,2,1, sharex=scat)
#histy=fig.add_subplot(2,2,4, sharey=scat)
# Scatter plot
scat.plot(X, Y,linestyle='none', marker='o', color='green', mec='green',alpha=.2, zorder=-99)
gkde = scipy.stats.gaussian_kde([X, Y])
x,y = numpy.mgrid[X.min():X.max():(X.max()-X.min())/25.,Y.min():Y.max():(Y.max()-Y.min())/25.]
z = numpy.array(gkde.evaluate([x.flatten(), y.flatten()])).reshape(x.shape)
scat.contour(x, y, z, linewidths=2)
scat.set_xlabel(xlabel)
scat.set_ylabel(ylabel)
# X-axis histogram
histx.hist(X, bins, histtype='stepfilled')
pylab.setp(histx.get_xticklabels(), visible=False) # no X label
#histx.xaxis.set_major_formatter(pylab.NullFormatter()) # no X label
# Y-axis histogram
histy.hist(Y, bins, histtype='stepfilled', orientation='horizontal')
pylab.setp(histy.get_yticklabels(), visible=False) # no Y label
#histy.yaxis.set_major_formatter(pylab.NullFormatter()) # no Y label
#pylab.minorticks_on()
#pylab.subplots_adjust(hspace=0.1)
#pylab.subplots_adjust(wspace=0.1)
pylab.draw()
pylab.show()
评论列表
文章目录