def edgescatter(self, ps):
for ei,X in enumerate(self.edges):
i,j = X[:2]
matchdRA, matchdDec = X[10:12]
mu = X[9]
A = self.alignments[ei]
plt.clf()
if len(matchdRA) > 1000:
plothist(matchdRA, matchdDec, 101)
else:
plt.plot(matchdRA, matchdDec, 'k.', alpha=0.5)
plt.axvline(0, color='0.5')
plt.axhline(0, color='0.5')
plt.axvline(mu[0], color='b')
plt.axhline(mu[1], color='b')
for nsig in [1,2]:
X,Y = A.getContours(nsigma=nsig)
plt.plot(X, Y, 'b-')
plt.xlabel('delta-RA (arcsec)')
plt.ylabel('delta-Dec (arcsec)')
plt.axis('scaled')
ps.savefig()
python类axvline()的实例源码
def plot_2D_contour(states,p,labels,inter=False):
import pylab as pl
from pyme.statistics import expectation as EXP
exp = EXP((states,p))
X = np.unique(states[0,:])
Y = np.unique(states[1,:])
X_len = len(X)
Y_len = len(Y)
Z = np.zeros((X.max()+1,Y.max()+1))
for i in range(len(p)):
Z[states[0,i],states[1,i]] = p[i]
Z = np.where(Z < 1e-8,0.0,Z)
pl.clf()
XX, YY = np.meshgrid(X,Y)
pl.contour(range(X.max()+1),range(Y.max()+1),Z.T)
pl.axhline(y=exp[1])
pl.axvline(x=exp[0])
pl.xlabel(labels[0])
pl.ylabel(labels[1])
if inter == True:
pl.draw()
else:
pl.show()
def plotalignment(A, nbins=200, M=None, rng=None, doclf=True, docolorbar=True,
docutcircle=True, docontours=True, dologhist=False,
doaxlines=False, imshowargs={}):
import pylab as plt
from astrometry.util.plotutils import plothist, loghist
if doclf:
plt.clf()
if M is None:
M = A.match
if dologhist:
f = loghist
else:
f = plothist
H,xe,ye = f(M.dra_arcsec*1000., M.ddec_arcsec*1000., nbins,
range=rng, doclf=doclf, docolorbar=docolorbar,
imshowargs=imshowargs)
ax = plt.axis()
if A is not None:
# The EM fit is based on a subset of the matches;
# draw the subset cut circle.
if docutcircle:
angle = np.linspace(0, 2.*pi, 360)
plt.plot((A.cutcenter[0] + A.cutrange * np.cos(angle))*1000.,
(A.cutcenter[1] + A.cutrange * np.sin(angle))*1000., 'r-')
if docontours:
for i,c in enumerate(['b','c','g']*2):
if i == A.ngauss:
break
for nsig in [1,2]:
XY = A.getContours(nsig, c=i)
if XY is None:
break
X,Y = XY
plt.plot(X*1000., Y*1000., '-', color=c)#, alpha=0.5)
if doaxlines:
plt.axhline(0., color='b', alpha=0.5)
plt.axvline(0., color='b', alpha=0.5)
plt.axis(ax)
plt.xlabel('dRA (mas)')
plt.ylabel('dDec (mas)')
return H,xe,ye
def plot_marginals(state_space,p,name,t,labels = False):
import matplotlib
#matplotlib.use("PDF")
#matplotlib.rcParams['figure.figsize'] = 5,10
import matplotlib.pyplot as pl
pl.suptitle("time: "+ str(t)+" units")
print("time : "+ str(t))
D = state_space.shape[1]
for i in range(D):
marg_X = np.unique(state_space[:,i])
A = np.where(marg_X[:,np.newaxis] == state_space[:,i].T[np.newaxis,:],1,0)
marg_p = np.dot(A,p)
pl.subplot(int(D/2)+1,2,i+1)
pl.plot(marg_X,marg_p)
pl.axvline(np.sum(marg_X*marg_p),color= 'r')
pl.axvline(marg_X[np.argmax(marg_p)],color='g')
if labels == False:
pl.xlabel("Specie: " + str(i+1))
else:
pl.xlabel(labels[i])
#pl.savefig("Visuals/marginal_"+name+".pdf",format='pdf')
pl.show()
pl.clf()
##Simple Compress : best N-term approximation under the ell_1 norm
#@param state_space the state space shape: (Number of Species X Number of states)
#@param p probability vector
#@param eps the ell_1 error to remove
#@return -Compressed state space
# -Compressed Probs
def plot_marginals(state_space,p,name,t,labels = False,interactive = False):
import matplotlib
import matplotlib.pyplot as pl
if interactive == True:
pl.ion()
pl.clf()
pl.suptitle("time: "+ str(t)+" units")
#print("time : "+ str(t))
D = state_space.shape[1]
for i in range(D):
marg_X = np.unique(state_space[:,i])
A = np.where(marg_X[:,np.newaxis] == state_space[:,i].T[np.newaxis,:],1,0)
marg_p = np.dot(A,p)
pl.subplot(int(D/2)+1,2,i+1)
pl.plot(marg_X,marg_p)
pl.yticks(np.linspace(np.amin(marg_p), np.amax(marg_p), num=3))
pl.axvline(np.sum(marg_X*marg_p),color= 'r')
pl.axvline(marg_X[np.argmax(marg_p)],color='g')
if labels == False:
pl.xlabel("Specie: " + str(i+1))
else:
pl.xlabel(labels[i])
if interactive == True:
pl.draw()
else:
pl.tight_layout()
pl.show()
def plotAgainstGFP(self, extradataA = [], extradataG = [], intensity = [], seq = []):
fig1 = pylab.figure(figsize = (25, 10))
print len(self.GFP)
for i in xrange(min(len(data.cat), 3)):
print len(self.GFP[self.categories == i])
vect = []
pylab.subplot(1,3,i+1)
#pylab.hist(self.GFP[self.categories == i], bins = 20, color = data.colors[i])
pop = self.GFP[self.categories == i]
pylab.plot(self.GFP[self.categories == i], self.angles[self.categories == i], data.colors[i]+'o', markersize = 8)#, label = data.cat[i])
print "cat", i, "n pop", len(self.GFP[(self.categories == i) & (self.GFP > -np.log(12.5))])
x = np.linspace(np.min(self.GFP[self.categories == i]), np.percentile(self.GFP[self.categories == i], 80),40)
#fig1.canvas.mpl_connect('pick_event', onpick)
for j in x:
vect.append(np.median(self.angles[(self.GFP > j) & (self.categories == i)]))
pylab.plot([-4.5, -0.5], [vect[0], vect[0]], data.colors[i], label = "mediane de la population entiere", linewidth = 5)
print vect[0], vect[np.argmax(x > -np.log(12.5))]
pylab.plot([-np.log(12.5), -0.5], [vect[np.argmax(x > -np.log(12.5))] for k in [0,1]], data.colors[i], label = "mediane de la population de droite", linewidth = 5, ls = '--')
pylab.axvline(x = -np.log(12.5), color = 'm', ls = '--', linewidth = 3)
pylab.xlim([-4.5, -0.5])
pylab.legend(loc = 2, prop = {'size':17})
pylab.title(data.cat[i].split(',')[0], fontsize = 24)
pylab.xlabel('score GFP', fontsize = 20)
pylab.ylabel('Angle (degre)', fontsize = 20)
pylab.tick_params(axis='both', which='major', labelsize=20)
pylab.ylim([-5, 105])
##pylab.xscale('log')
pylab.show()