本文整理汇总了Python中matplotlib.ticker.ScalarFormatter.format_data方法的典型用法代码示例。如果您正苦于以下问题:Python ScalarFormatter.format_data方法的具体用法?Python ScalarFormatter.format_data怎么用?Python ScalarFormatter.format_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.ticker.ScalarFormatter
的用法示例。
在下文中一共展示了ScalarFormatter.format_data方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compare_plots_one_param_line_hist
# 需要导入模块: from matplotlib.ticker import ScalarFormatter [as 别名]
# 或者: from matplotlib.ticker.ScalarFormatter import format_data [as 别名]
def compare_plots_one_param_line_hist(list_of_pos_by_name,param,cl,color_by_name,cl_lines_flag=True,legend='right',analyticPDF=None):
"""
Plots a gaussian kernel density estimate for a set
of Posteriors onto the same axis.
@param list_of_pos: a list of Posterior class instances.
@param plot1DParams: a dict; {paramName:Nbins}
"""
from scipy import seterr as sp_seterr
#Create common figure
myfig=plt.figure(figsize=(6,4.5),dpi=150)
#myfig.add_axes([0.1,0.1,0.65,0.85])
#myfig.add_axes([0.15,0.15,0.6,0.76])
axes=plt.Axes(myfig,[0.15,0.15,0.6,0.76])
myfig.add_axes(axes)
majorFormatterX=ScalarFormatter(useMathText=True)
majorFormatterX.format_data=lambda data:'%.6g'%(data)
majorFormatterY=ScalarFormatter(useMathText=True)
majorFormatterY.format_data=lambda data:'%.6g'%(data)
majorFormatterX.set_scientific(True)
majorFormatterY.set_scientific(True)
list_of_pos=list_of_pos_by_name.values()
list_of_pos_names=list_of_pos_by_name.keys()
allmins=map(lambda a: np.min(a[param].samples), list_of_pos)
allmaxes=map(lambda a: np.max(a[param].samples), list_of_pos)
min_pos=np.min(allmins)
max_pos=np.max(allmaxes)
injvals=[]
patch_list=[]
max_y=0
posbins=np.linspace(min_pos,max_pos,50)
for name,posterior in list_of_pos_by_name.items():
colour=color_by_name[name]
#myfig.gca(autoscale_on=True)
if posterior[param].injval:
injvals.append(posterior[param].injval)
try:
n,bins=np.histogram(posterior[param].samples,bins=posbins,normed=True,new=True)
except:
n,bins=np.histogram(posterior[param].samples,bins=posbins,normed=True)
if min(bins)==max(bins):
print 'Skipping '+param
continue
locmaxy=max(n)
if locmaxy>max_y: max_y=locmaxy
#(n, bins, patches)=plt.hist(posterior[param].samples,bins=bins,facecolor='white',label=name,normed=True,hold=True,color=color_by_name[name])#range=(min_pos,max_pos)
(n, bins, patches)=plt.hist(posterior[param].samples,bins=bins,histtype='step',label=name,normed=True,hold=True,color=color_by_name[name])
patch_list.append(patches[0])
Nchars=max(map(lambda d:len(majorFormatterX.format_data(d)),axes.get_xticks()))
if Nchars>8:
Nticks=3
elif Nchars>5:
Nticks=4
elif Nchars>4:
Nticks=6
else:
Nticks=6
locatorX=mpl.ticker.MaxNLocator(nbins=Nticks)
locatorX.view_limits(bins[0],bins[-1])
axes.xaxis.set_major_locator(locatorX)
plt.xlim(min_pos,max_pos)
top_cl_intervals_list={}
pos_names=list_of_pos_by_name.keys()
for name,posterior in list_of_pos_by_name.items():
#toppoints,injectionconfidence,reses,injection_area,cl_intervals=bppu.greedy_bin_one_param(posterior,{param:greedyBinSizes[param]},[cl])
cl_intervals=posterior[param].prob_interval([cl])
colour=color_by_name[name]
if cl_intervals[0] is not None and cl_lines_flag:
try:
plt.plot([cl_intervals[0][0],cl_intervals[0][0]],[0,max_y],color=colour,linestyle='--')
plt.plot([cl_intervals[0][1],cl_intervals[0][1]],[0,max_y],color=colour,linestyle='--')
except:
print "MAX_Y",max_y,[cl_intervals[0][0],cl_intervals[0][0]],[cl_intervals[0][1],cl_intervals[0][1]]
top_cl_intervals_list[name]=(cl_intervals[0][0],cl_intervals[0][1])
if cl_lines_flag:
pos_names.append(str(int(cl*100))+'%')
patch_list.append(mpl.lines.Line2D(np.array([0.,1.]),np.array([0.,1.]),linestyle='--',color='black'))
plt.grid()
plt.xlim(min_pos,max_pos)
if legend is not None:
oned_legend=plt.figlegend(patch_list,pos_names,'right')
#.........这里部分代码省略.........