Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing contour levels inline for each line #223

Open
neuronphysics opened this issue Oct 10, 2014 · 0 comments
Open

Writing contour levels inline for each line #223

neuronphysics opened this issue Oct 10, 2014 · 0 comments

Comments

@neuronphysics
Copy link

I am trying to overlay contours on an image but I would like to use clabel and put some inline scales on the image but I wasn't successful and I couldn't find anything useful in the documentation of Aplpy
What I have written so far is like this :
def get_contour_verts(cn):
contours = []
# for each contour line
for cc in cn.collections:
paths = []
# for each separate section of the contour line
for pp in cc.get_paths():
xy = []
# for each segment of that section
for vv in pp.iter_segments():
xy.append(vv[0])
paths.append(np.vstack(xy))
contours.append(paths)
return contours

lev_exp = np.arange(np.floor(np.log10(zp.min())-1), np.ceil(np.log10(zp.max())+1))
levs = np.power(10, lev_exp)
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.7
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=levs,extent=extent,norm=LogNorm())
Contour_arrays=get_contour_verts(CS)
for contours_at_level,c in zip(Contour_arrays,colors):
clines = [cl.T for cl in contours_at_level]
img.show_lines(clines[3:],color='white',layer='contour_set_1',linestyle='solid', linewidth=0.15, zorder=100)
img._layers['contour_set_1'].clabel(clines[3:], inline=1, fontsize=20., fmt=ticker.LogFormatterMathtext())
img.save('image_rgb_arcsinh_contour.pdf')
The error:
  File "Plot.Contour.Red.Galaxies.py", line 237, in
    img._layers['contour_set_1'].clabel(clines[3:], inline=1, fontsize=20., fmt=ticker.Log
FormatterMathtext())
AttributeError: 'LineCollection' object has no attribute 'clabel'
Is it possible to write the contour level over each line?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant