本文整理汇总了Python中Graphics.adjust_spines方法的典型用法代码示例。如果您正苦于以下问题:Python Graphics.adjust_spines方法的具体用法?Python Graphics.adjust_spines怎么用?Python Graphics.adjust_spines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graphics
的用法示例。
在下文中一共展示了Graphics.adjust_spines方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: frequencies
# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import adjust_spines [as 别名]
def frequencies(self,str, ax=None, cutoff=30):
words = nltk.word_tokenize(''.join(ch for ch in str
if ch not in exclude
and ord(ch)<128
and not ch.isdigit()).lower())
words = [word for word in words if word not in stopwords
and word not in emoticons
and word not in ['rt','amp']]
fdist = nltk.FreqDist(words)
freqs = fdist.items()[:cutoff]
word,f =zip(*freqs)
f = np.array(f).astype(float)
print f,'kkkkkkk'
f /= float(f.sum())
print f,'jjjjjjjjjjjj'
if not ax:
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(-f*np.log(f),'k',linewidth=2)
artist.adjust_spines(ax)
ax.yaxis.grid()
ax.xaxis.grid()
ax.set_xticks(range(len(word)))
ax.set_xticklabels(map(format,word),range(len(word)), rotation=45)
ax.set_ylabel(r'\Large $\log \left(\mathbf{Frequency}\right)$')
plt.tight_layout()
plt.show()
示例2: covariance
# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import adjust_spines [as 别名]
def covariance(heatmap,labels,show=False,savename=None,ml=False):
#Covariance matrix
fig = plt.figure(figsize=(13,13))
ax = fig.add_subplot(111)
cax = ax.imshow(heatmap,interpolation='nearest',aspect='equal')
artist.adjust_spines(ax)
ax.set_xticks(range(len(labels)))
ax.set_xticklabels(map(artist.format,labels),range(len(labels)),rotation=90)
ax.set_yticks(range(len(labels)))
ax.set_yticklabels(map(artist.format,labels))
if ml:
ax.annotate(r'\LARGE \textbf{Training}', xy=(.2, .2), xycoords='axes fraction',
horizontalalignment='center', verticalalignment='center')
ax.annotate(r'\LARGE \textbf{Testing}', xy=(.7, .7), xycoords='axes fraction',
horizontalalignment='center', verticalalignment='center')
plt.colorbar(cax, fraction=0.10, shrink=0.8)
plt.tight_layout()
if savename:
plt.savefig('%s.png'%savename,dpi=200)
if show:
plt.show()
示例3: plot_variable
# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import adjust_spines [as 别名]
def plot_variable(data,basepath=None,dataname='',criterion=None, criterionname=[]):
fig = plt.figure()
ax = fig.add_subplot(111)
x = range(data.shape[1])
ap('Plotting %s'%dataname)
if criterion != None:
if type(criterion) != list:
median, lq, uq = perc(data[criterion,:])
ax.plot(x,median,linewidth=2, color='#B22400')
ax.fill_between(x, lq, uq, alpha=0.25, linewidth=0, color='#B22400')
else:
bmap = brewer2mpl.get_map('Set2', 'qualitative', 7)
colors = bmap.mpl_colors
for i,(x_criterion,x_label) in enumerate(itertools.izip_longest(criterion,criterionname,fillvalue='Group')):
median, lq, uq = perc(data[x_criterion,:])
ax.plot(x,median,linewidth=2, color=colors[i], label=artist.format(x_label))
ax.fill_between(x, lq, uq, alpha=0.25, linewidth=0, color=colors[i])
median, lq, uq = perc(data)
ax.plot(x,median,linewidth=2, color='#B22400',label=artist.format('Full population'))
ax.fill_between(x, lq, uq, alpha=0.25, linewidth=0, color='#B22400')
artist.adjust_spines(ax)
ax.set_ylabel(artist.format(dataname))
ax.set_xlabel(artist.format('Time'))
ax.axvline(data.shape[1]/3,color='r',linewidth=2,linestyle='--')
ax.axvline(2*data.shape[1]/3,color='r',linewidth=2,linestyle='--')
plt.legend(frameon=False,loc='lower left')
plt.tight_layout()
plt.savefig(os.path.join(basepath,'%s.png'%dataname))
示例4: snapshots
# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import adjust_spines [as 别名]
def snapshots(data, indices,basepath=None, data_label='data'):
indices = zip(indices,indices[1:])
for start_idx,stop_idx in indices:
initial_distribution = data[:,start_idx]
final_distribution = data[:,stop_idx]
fig = plt.figure()
ax = fig.add_subplot(111)
ax.hist(initial_distribution,color='r',alpha=0.5,bins=20,label='Initial', range=(-1,1))
ax.hist(final_distribution,color='k',alpha=0.5,bins=20,label='Final',range=(-1,1))
artist.adjust_spines(ax)
ax.set_xlabel(artist.format(data_label))
ax.set_ylabel(artist.format('Prevalence'))
H,p =kruskal(initial_distribution,final_distribution)
effect_size = np.linalg.norm(final_distribution-initial_distribution)
ax.annotate('\Large $d=%.02f, \; p=%.04f$'%(effect_size,p), xy=(.3, .9),
xycoords='axes fraction', horizontalalignment='right', verticalalignment='top')
plt.tight_layout()
plt.legend(frameon=False)
filename = os.path.join(basepath,'%s-compare-%d-%d.png'%(data_label,start_idx,stop_idx))
plt.savefig(filename,dpi=300)
plt.close()
示例5: ecdf
# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import adjust_spines [as 别名]
def ecdf(data, show=False,savename=None):
ecdf = sm.distributions.ECDF(data)
x = np.linspace(data.min(),data.max())
y = ecdf(x)
cutoff = x[y>0.85][0]
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x,y,'k',linewidth=3)
artist.adjust_spines(ax)
ax.annotate(r'\Large \textbf{Cutoff:} $%.03f$'%cutoff, xy=(.3, .2), xycoords='axes fraction',
horizontalalignment='center', verticalalignment='center')
ax.set_xlabel(artist.format('Absolute Correlation'))
ax.set_ylabel(artist.format('Percentile'))
ax.axhline(y=0.85,color='r',linestyle='--',linewidth=2)
ax.axvline(x=cutoff,color='r',linestyle='--',linewidth=2)
ax.set_xlim((0,1))
plt.tight_layout()
if savename:
plt.savefig('%s.png'%savename,dpi=200)
if show:
plt.show()
return cutoff
示例6: coefficients
# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import adjust_spines [as 别名]
def coefficients(model,labels,show=False,savename=None,title=None):
fig = plt.figure(figsize=(8,10))
ax = fig.add_subplot(111)
x = -model.coef_.transpose()
x /= np.absolute(x).max()
y = np.arange(len(x))+0.5
cutoff = scoreatpercentile(np.absolute(x),85)
ax.barh(y,x,color=['r' if datum < 0 else 'g' for datum in x])
ax.axvline(cutoff,linewidth=2,linestyle='--',color='r')
ax.axvline(-cutoff,linewidth=2,linestyle='--',color='r')
artist.adjust_spines(ax)
ax.grid(True)
ax.set_ylim(ymax=62)
ax.set_xlim(xmin=-1.1,xmax=1.1)
ax.set_yticks(y)
ax.set_yticklabels(map(format,labels),y)
ax.set_xlabel(format('Regression coefficient'))
if title:
ax.set_title(r'\Large \textbf{%s}'%title)
plt.tight_layout()
if show:
plt.show()
示例7: plot
# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import adjust_spines [as 别名]
def plot(aList,ax, cutoff=20):
tokens,frequencies = zip(*sorted(aList,key=lambda item:item[1],reverse=True))
tokens = tokens[:cutoff][::-1]
frequencies = frequencies[:cutoff][::-1]
ax.plot(frequencies,xrange(cutoff),'k--', linewidth=2)
artist.adjust_spines(ax)
ax.set_yticks(xrange(cutoff))
ax.set_yticklabels(map(artist.format,tokens),rotation='horizontal')
示例8: network_stability
# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import adjust_spines [as 别名]
def network_stability(energy_trace,savename):
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(energy_trace,'k',linewidth=2)
artist.adjust_spines(ax)
ax.set_xlabel(artist.format('Time'))
ax.set_ylabel(artist.format('Stability (energy)'))
plt.savefig('%s.png'%savename,dpi=200)
plt.close()
示例9: plot_and_save
# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import adjust_spines [as 别名]
def plot_and_save(frequencies, words, ylabel, savefile):
fig = plt.figure()
ax = fig.add_subplot(111)
ax.semilogy(frequencies,'k--',linewidth=3)
artist.adjust_spines(ax)
ax.set_xticks(xrange(len(words)))
ax.set_xticklabels([r'\textbf{\textsc{%s}'%word for word in words],rotation='vertical')
ax.set_ylabel(artist.format(ylabel))
plt.tight_layout()
plt.show()
plt.savefig(savefile, bbox_inches="tight")
示例10: memory_stability
# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import adjust_spines [as 别名]
def memory_stability(mat,savename):
fig = plt.figure()
ax = fig.add_subplot(111)
cax = ax.imshow(mat,interpolation='nearest',aspect='auto')
artist.adjust_spines(ax)
ax.set_ylabel(artist.format('Memory'))
ax.set_xlabel(artist.format('Time'))
cbar = plt.colorbar(cax)
cbar.set_label(artist.format('Energy'))
plt.savefig('%s.png'%savename,dpi=200)
plt.close()
示例11: hist_compare
# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import adjust_spines [as 别名]
def hist_compare(data,criterion=None, basepath=None, criterionname='Target population',fieldname='Field'):
del fig,ax
fig = plt.figure()
ax = fig.add_subplot(111)
ax.hist(data,color='k',histtype='step',label=artist.format('Full Population'))
plt.hold(True)
if criterion:
ax.hist(data[criterion],color='r',histtype='stepfilled',label=artist.format(criterionname))
artist.adjust_spines(ax)
ax.set_xlabel(artist.format(fieldname))
ax.set_ylabel(artist.format('No. of people '))
plt.legend(frameon=False)
plt.tight_layout()
plt.savefig(os.path.join(basepath,'hist_compare_full_%s'%('_'.join(criterion.split()))),dpi=300)
示例12: sensitivity
# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import adjust_spines [as 别名]
def sensitivity(x,y, show=False, savename=None):
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x,y,'ko--',linewidth=2,clip_on=False)
artist.adjust_spines(ax)
ax.set_xlabel(r'\Large \textbf{Mixing fraction,} $\; \alpha$')
ax.set_ylabel(r'\Large \textbf{Maximum accuracy,}$\; q_{\max}$')
ax.set_ylim((-1.1))
plt.tight_layout()
if savename:
plt.savefig('%s.png'%savename,dpi=300)
if show:
plt.show()
plt.close()
return pearsonr(x,y)
示例13: mvr_coefficients
# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import adjust_spines [as 别名]
def mvr_coefficients(model,labels,show=False,savename=None):
fig = plt.figure()
ax = fig.add_subplot(111)
cax = ax.imshow(model.coef_.transpose(),interpolation='nearest',aspect='auto',
vmin=-0.5,vmax=0.5)
artist.adjust_spines(ax)
ax.set_yticks(range(len(labels)))
ax.set_yticklabels(map(artist.format,[name for name in labels if 'EVD' not in name]))
ax.set_xticks(range(3))
ax.set_xticklabels(map(artist.format,range(1,4)))
ax.set_xlabel(artist.format('Placement grade'))
plt.colorbar(cax)
plt.tight_layout()
if savename:
plt.savefig('%s.png'%savename,dpi=200)
if show:
plt.show()
示例14: population_summary
# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import adjust_spines [as 别名]
def population_summary(basepath=None, criterion = None, criterionname=''):
yvars = open(directory['variables'],READ).read().splitlines()
yvars.remove('past month drinking')
ncols = np.ceil(np.sqrt(len(yvars))).astype(int)
nrows = np.ceil(len(yvars)/ncols).astype(int)
MALE = 0.5
FEMALE = 0.3
fig,axs = plt.subplots(nrows=nrows,ncols=ncols,sharey=True)
for i,col in enumerate(axs):
for j,row in enumerate(col):
filename = 'initial-distribution-%s.txt'%(yvars[i*ncols+j].replace(' ','-'))
data = np.loadtxt(os.path.join(basepath,filename),delimiter=TAB)
if criterion:
weights = np.ones_like(data[criterion])/len(data[criterion])
_,_,patches1 = axs[i,j].hist(data[criterion],color='r',alpha=0.5,
label=artist.format(criterionname),histtype='step',weights=weights)
plt.hold(True)
weights = np.ones_like(data)/len(data)
_,_,patches2 = axs[i,j].hist(data, color='k',label=artist.format('Full population'),
histtype='stepfilled' if not criterion else 'step',weights=weights)
fig.canvas.mpl_connect('draw_event', artist.on_draw)
artist.adjust_spines(axs[i,j])
if 'attitude' not in yvars[i*ncols+j]:
axs[i,j].set_xlabel(artist.format(yvars[i*ncols+j].replace('drink','use')))
if 'gender' in yvars[i*ncols+j]:
axs[i,j].set_xticks([FEMALE,MALE])
axs[i,j].set_xticklabels(map(artist.format,['Female','Male']))
elif 'psychological' in yvars[i*ncols+j]:
label = '\n'.join(map(artist.format,['Attitude to','psychological','consequences']))
axs[i,j].set_xlabel(label)
elif 'medical' in yvars[i*ncols+j]:
label = '\n'.join(map(artist.format,['Attitude','to medical','consequences']))
axs[i,j].set_xlabel(label)
#axs[i,j].set_xlim([-50,50])
plt.tight_layout()
if criterion:
fig.legend((patches1[0], patches2[0]), (artist.format(criterionname),artist.format('Full population')),
loc='lower right', frameon=False, ncol=2)
filename = os.path.join(os.getcwd(),basepath,'dashboard.png' if criterionname == '' else 'dashboard-%-s.png'%criterionname)
plt.savefig(filename,dpi=300)
示例15: correlation_visualization
# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import adjust_spines [as 别名]
def correlation_visualization(data, show=False,savename=None):
correlations = ['Quu','Qru','Qvu']
#Analyze correlations
fig,axs = plt.subplots(nrows=3,ncols=1,sharex=True)
for ax,data,label in zip(axs,map(dq,[data[correlation] for correlation in correlations]),correlations):
ax.plot(data,'k',linewidth=2,label=artist.format(label))
artist.adjust_spines(ax)
ax.set_ylabel(r'\Large $\mathbf{\partial \left(\det %s_{%s}\right)}$'%(label[0],label[1:]),rotation='horizontal')
ax.set_xlabel(artist.format('Time'))
plt.tight_layout()
if savename:
plt.savefig('%s.png'%savename,dpi=200)
if show:
plt.show()
plt.close()