2014-10-12 87 views
0

我正在尝试在天文图像上叠加等高线图。下面的代码显示了如何生成我的等值线:更改clabel的位置和标签

print "contour map " 
ny, nx = 50, 50 
level=np.array([0.683,0.866,0.954,0.990, 0.997]) 
print "limits:" 
print 
print level 
print 
bins_x=np.linspace(min(xp),max(xp),nx) 
bins_y=np.linspace(min(yp),max(yp),ny) 
H, yedges, xedges = np.histogram2d(xp, yp, (bins_x,bins_y),weights=zp) 
smooth=0.8 
Hsmooth = scipy.ndimage.filters.gaussian_filter(H.T, smooth) 
xcenters = (xedges[1:] + xedges[:-1])/2. 
ycenters = (yedges[1:] + yedges[:-1])/2. 
Xgrid, Ygrid = np.meshgrid(ycenters, xcenters) 
extent = [xedges[0], xedges[-1], yedges[0], yedges[-1] ] 
print len(ra),len(Gcl_1_ra),len(Gcl_2_ra) 
# Now we add contours 
CS = plt.contour(Xgrid, Ygrid, Hsmooth, levels=level, extent=extent, linewidths=0.4, cmap=cm.Pastel1) 

print CS.levels 
plt.clabel(CS, CS.levels, colors='red',inline=True, inline_spacing=0.02,fontsize=7, fmt="%0.3f") 

print "label coordinate :" 
print CS.cl_xy 
plt.show() 

运行的代码给我约了轮廓标签放置的信息:

label coordinate : 
[(479.11978392445798, 152.0), (183.33333333333337, 234.5705217606079), (394.86796408013157, 336.0), (462.33333333333337, 156.69957238363236), (183.33333333333337, 232.80998335706244), (399.34062255451977, 296.0), (462.33333333333337, 155.83083286816793), (183.33333333333337, 231.97448760480535), (402.06057288711821, 320.00000000000006), (452.00000000000006, 152.37778562776006), (183.33333333333337, 231.73316562697329), (399.50827125157235, 328.0), (452.00000000000006, 152.25467967915702), (183.33333333333337, 231.68624190906149), (399.44091390280244, 328.0)] 

我的问题是

  1. 由于轮廓的标签总是相互重叠,我怎么可以取代标签以避免混淆? enter image description here

  2. 我想将clabel的标签更改为label=[r'1$\sigma$',r'1.5$\sigma$',r'2$\sigma$',r'2.6$\sigma$',r'3$\sigma$']。我怎么能这样做?

在此先感谢。

+0

为了解决重叠,为什么包括所有的级别?或者,您可以对不同的轮廓进行颜色编码或线条编码。 – mdurant 2014-10-12 01:03:10

+0

@mdurant你能解释一下我可以做些什么** linestyle-code不同的轮廓**? – Dalek 2014-10-12 01:27:58

+1

'[c.set_linestyle(s)in zip(CS.collections,[' - ',':',' - '] * 5)]' – mdurant 2014-10-12 02:37:53

回答

2

对于1),可以通过一组x,y值来clabel,在那里你想放置

manual=[(x1,y1),(x2,y2)... 

对于2标签),可以传递FMT作为函数被调用与每个数值,它返回一个字符串标签;或字典。对你来说,它可能是

fmt={0.683:r'1$sigma$', 0.866:r'1.5$sigma$', 0.954:r'2$sigma$', 
     0.990:r'2.6$sigma$', 0.997:r'3$sigma$'}