当前位置: 首页>>代码示例>>Python>>正文


Python Graphics.format方法代码示例

本文整理汇总了Python中Graphics.format方法的典型用法代码示例。如果您正苦于以下问题:Python Graphics.format方法的具体用法?Python Graphics.format怎么用?Python Graphics.format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Graphics的用法示例。


在下文中一共展示了Graphics.format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ecdf

# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import format [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
开发者ID:mac389,项目名称:clinic,代码行数:30,代码来源:visualization.py

示例2: snapshots

# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import format [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()
开发者ID:mac389,项目名称:at-risk-agents,代码行数:27,代码来源:visualization.py

示例3: plot_variable

# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import format [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))
开发者ID:mac389,项目名称:at-risk-agents,代码行数:32,代码来源:visualization.py

示例4: network_stability

# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import format [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()
开发者ID:mac389,项目名称:synchrony,代码行数:13,代码来源:visualization.py

示例5: memory_stability

# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import format [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()
开发者ID:mac389,项目名称:synchrony,代码行数:16,代码来源:visualization.py

示例6: hist_compare

# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import format [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)
开发者ID:mac389,项目名称:at-risk-agents,代码行数:17,代码来源:visualization.py

示例7: population_summary

# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import format [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)
开发者ID:mac389,项目名称:at-risk-agents,代码行数:46,代码来源:visualization.py

示例8: correlation_visualization

# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import format [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()
开发者ID:mac389,项目名称:synchrony,代码行数:21,代码来源:analysis.py

示例9: compare_demographics

# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import format [as 别名]
def compare_demographics(data,nrows=2,ncols=3):
	#Data is a list of tuples of (label,data,color)
	fig,axs = plt.subplots(nrows=nrows,ncols=ncols,sharex=False,sharey=True)
	first_label,first_idx,first_color = data[0]
	second_label,second_idx,second_color = data[1]

	MALE = 0.5
	FEMALE = 0.3
	for i,col in enumerate(axs):
		for j,row in enumerate(col):
				characteristic = characteristics[i*ncols+j]
				uq = demographics[characteristic][first_idx]
				lq = demographics[characteristic][second_idx]
						
				_,_,patches1=row.hist(uq,color=first_color,label=artist.format(first_label), histtype='step',
					weights = np.ones_like(uq)/len(uq))
				plt.hold(True)
				_,_,patches2=row.hist(lq,color=second_color,label=artist.format(second_label),histtype='step',
					weights=np.ones_like(lq)/len(lq))
				fig.canvas.mpl_connect('draw_event', artist.on_draw)
				artist.adjust_spines(row)
				if 'attitude' not in yvars[i*ncols+j]: 	
					row.set_xlabel(artist.format(yvars[i*ncols+j]))
					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']))
					row.set_xlabel(label)
				elif 'medical' in yvars[i*ncols+j]:
					label = '\n'.join(map(artist.format,['Attitude','to medical','consequences']))
					row.set_xlabel(label)
					#axs[i,j].set_xlim([-50,50])

	plt.tight_layout()
	fig.legend((patches1[0], patches2[0]), (artist.format(first_label),artist.format(second_label)),
		loc='lower right', frameon=False, ncol=2)
	#filename = os.path.join(os.getcwd(),basepath,'compare-quartile-demographics-no-temporal-threshold.png')
	filename = os.path.join(os.getcwd(),basepath,'compare-quartile-demographics-%s-vs-%s.png'%(first_label,second_label))
	plt.savefig(filename,dpi=300)
	del fig,axs,i,j
开发者ID:mac389,项目名称:at-risk-agents,代码行数:43,代码来源:analyze-intervention.py

示例10: compare_distributions

# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import format [as 别名]
def compare_distributions(variable_source_name,idxs,rng=(0,1)):
	#Assume idxs is dictionary structured as {name:[corresponding indices]}
	fig = plt.figure()
	ax = fig.add_subplot(111)
	data =  np.loadtxt(make_filename('%s.txt'%(variable_source_name)),delimiter=TAB)

	fig = plt.figure()
	ax = fig.add_subplot(111)
	plt.hold(True)
	for subpopulation,idx,color in idxs:
		weights = np.ones_like(data[idx])/len(data[idx])
		ax.hist(data[idx],color=color,label=artist.format(subpopulation),histtype='step',range=rng,weights=weights)

	fig.canvas.mpl_connect('draw_event', artist.on_draw)
	artist.adjust_spines(ax)
	ax.set_ylabel(artist.format('Prevalance'))
	ax.set_xlabel(artist.format(variable_source_name))
	plt.legend(frameon=False,ncol=2,loc='upper center',bbox_to_anchor=(.5,1.05))
	plt.tight_layout()
	plt.savefig(make_filename('%s-%s.png'%(variable_source_name,'-'.join([idx[0] for idx in idxs]))),dpi=300)
	del fig,ax
开发者ID:mac389,项目名称:at-risk-agents,代码行数:23,代码来源:analyze-intervention.py

示例11: plot_and_save

# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import format [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")
开发者ID:mac389,项目名称:computational-medical-knowledge,代码行数:15,代码来源:plotSave.py

示例12: accuracy_plot

# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import format [as 别名]
def accuracy_plot(start,accuracy, stop, memory,idx=0,savename=''):

	fig = plt.figure()
	start_plot = plt.subplot2grid((1,5),(0,0))
	accuracy_p = plt.subplot2grid((1,5),(0,1),colspan=2)
	end_plot = plt.subplot2grid((1,5),(0,3))
	target_plot = plt.subplot2grid((1,5),(0,4))
	
	parameters = {'interpolation':'nearest','aspect':'auto', 'cmap':plt.cm.binary}

	start_plot.imshow(start[:,np.newaxis],**parameters)
	accuracy_p.plot(accuracy,'k',linewidth=2)
	end_plot.imshow(stop[:,np.newaxis],**parameters)
	target_plot.imshow(memory[:,np.newaxis],**parameters)

	artist.adjust_spines(accuracy_p)

	for ax in [start_plot,end_plot,target_plot]:
		artist.adjust_spines(ax,['left'])

	accuracy_p.annotate(r'\Large $q\left(t\right) = \frac{1}{N} \mathbf{v}\left(t\right)\cdot \mathbf{v_{target}}$', 
		xy=(.6, .2),  xycoords='axes fraction',horizontalalignment='center', verticalalignment='center')

	accuracy_p.set_ylim((-1,1))

	start_plot.set_xticklabels([])
	start_plot.set_xlabel(artist.format('Start'))

	end_plot.set_xticklabels([])
	end_plot.set_xlabel(artist.format('End'))
	
	target_plot.set_xticklabels([])
	target_plot.set_xlabel(artist.format('Target'))

	fig.tight_layout()
	if savename:
		plt.savefig('%s-memory-%d.png'%(savename,idx),dpi=200)
	plt.close()
开发者ID:mac389,项目名称:synchrony,代码行数:40,代码来源:visualization.py

示例13: time_series

# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import format [as 别名]
def time_series(basepath=None, criterion=None, criterionname=''):
	filename = os.path.join(basepath,'attitudes.txt')
	attitudes = np.loadtxt(filename,delimiter=TAB)
	fig = plt.figure()
	ax = fig.add_subplot(111)
	#ax.fill_between(xrange(attitudes.shape[1]), attitudes.mean(axis=0)-attitudes.std(axis=0),
    #            attitudes.mean(axis=0) + attitudes.std(axis=0), color='k', alpha=0.4,
    #            label=artist.format('Full population'))
	ax.errorbar(xrange(attitudes.shape[1]),attitudes.mean(axis=0),yerr=(attitudes.std(axis=0)/attitudes.shape[0]))
#	ax.plot(xrange(attitudes.shape[1]),attitudes.mean(axis=0),color='k',linewidth=2)
	if criterion:
		data = attitudes[criterion]
		ax.fill_between(xrange(data.shape[1]), data.mean(axis=0)-data.std(axis=0),
                data.mean(axis=0) + data.std(axis=0), color='r', alpha=0.4,
                label=artist.format('criterionname'))
		ax.plot(xrange(data.shape[1]),data.mean(axis=0),color='r',linewidth=2)
	artist.adjust_spines(ax)
	ax.axvline(attitudes.shape[1]/3.,color='r',linewidth=2,linestyle='--') #This is a hack
	ax.axvline(2*attitudes.shape[1]/3.,color='r',linewidth=2,linestyle='--') #This is a hack
	ax.set_ylabel(artist.format('Intent to drink'))
	ax.set_xlabel(artist.format('Time'))
	ax.set_ylim(ymin=0)
	filename = os.path.join(os.getcwd(),basepath,'timecourse.png' if criterionname == '' else 'timecourse-%s.png'%criterionname)
	plt.savefig(filename,dpi=300)
开发者ID:mac389,项目名称:at-risk-agents,代码行数:26,代码来源:visualization.py

示例14: mvr_coefficients

# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import format [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()
开发者ID:mac389,项目名称:clinic,代码行数:20,代码来源:visualization.py

示例15: show_drinking_behavior

# 需要导入模块: import Graphics [as 别名]
# 或者: from Graphics import format [as 别名]
def show_drinking_behavior(basepath=None,compare_distributions=True,
	visualize_one_random_actor=False, visualize_all_actors=True):
	agents = np.loadtxt(os.path.join(basepath,'responders'),delimiter=TAB)
	filename = os.path.join(basepath,'drinking-behavior.txt')
	drinking_behavior = np.loadtxt(filename,delimiter=TAB)

	if compare_distributions:		
		fig = plt.figure()
		ax = fig.add_subplot(111)
		H,p = kruskal(drinking_behavior[:,INITIAL],drinking_behavior[:,END])

		initial_distribution = drinking_behavior[:,INITIAL]
		final_distribution = drinking_behavior[:,END]

		low = min(initial_distribution.min(),final_distribution.min())
		high = max(initial_distribution.max(),final_distribution.max())

		ax.hist(initial_distribution,color='r',alpha=0.5,bins=20,label='Initial',range=(low,high))
		ax.hist(final_distribution,color='k',alpha=0.5,bins=20,label='Final', range=(low,high))
		artist.adjust_spines(ax)
		ax.set_xlabel(artist.format('Intent to drink'))
		ax.set_ylabel(artist.format('Prevalence'))
		plt.legend(frameon=False)
		filename = os.path.join(os.getcwd(),basepath,'drinking-behavior-compare-distributions.png')
		plt.savefig(filename,dpi=300)

	if visualize_one_random_actor:
		fig = plt.figure()
		ax = fig.add_subplot(111)
		random_actor = random.choice(xrange(drinking_behavior.shape[0]))
		ax.plot(drinking_behavior[random_actor,:],'k--',linewidth=2)
		artist.adjust_spines(ax)
		ax.set_ylabel(artist.format('Past drinking behavior'))
		ax.set_xlabel(artist.format('Time'))
		filename = os.path.join(os.getcwd(),basepath,'drinking-behavior-visualize-actor.png')	
		plt.savefig(filename,dpi=300)

	if visualize_all_actors:
		fig = plt.figure()
		ax = fig.add_subplot(111)
		cax = ax.imshow(drinking_behavior,interpolation='nearest',aspect='auto')
		artist.adjust_spines(ax)
		ax.set_ylabel(artist.format('Actor'))
		ax.set_xlabel(artist.format('Time'))
		plt.colorbar(cax)
		filename = os.path.join(os.getcwd(),basepath,'drinking-behavior-visualize-all-actors.png')		
		plt.savefig(filename,dpi=300)
开发者ID:mac389,项目名称:at-risk-agents,代码行数:49,代码来源:visualization.py


注:本文中的Graphics.format方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。