【发布时间】:2019-03-16 22:46:18
【问题描述】:
【问题讨论】:
-
情节和括号之间的浅蓝色圆点背后的秘密是什么?
标签: python matplotlib plot heatmap
【问题讨论】:
标签: python matplotlib plot heatmap
在下面,我定义了一个函数,它根据输入的左下角、宽度和高度创建一个花括号补丁。
然后可以在循环中使用它以及带的宽度和位置列表及其名称。
请注意:作为第一次尝试,这种方法仍有一些缺点:
plt.style.use('ggplot')),它就不会再出现了。我认为这是因为 ggplo-style 及其 z-order 使用了一些补丁,但到目前为止,我无法解决这个问题。 代码:
def CurlyBrace(ll_corner=(0, 0), width=1, height=1):
import matplotlib.path as mpath
import matplotlib.patches as mpatches
import numpy as np
Path = mpath.Path
verts = np.array([(0, 0), (.5, 0), (.5, .2), (.5, .3), (.5, .5), (1, .5), (.5, .5), (.5, .7), (.5, .8), (.5, 1), (0, 1)])
verts[:, 0] *= width
verts[:, 1] *= height
verts[:, 0] += ll_corner[0]
verts[:, 1] += ll_corner[1]
cb_patch = mpatches.PathPatch(
Path(verts,
[Path.MOVETO, Path.CURVE3, Path.CURVE3, Path.LINETO, Path.CURVE3, Path.CURVE3, Path.CURVE3, Path.CURVE3, Path.LINETO, Path.CURVE3, Path.CURVE3]),
fc="none", clip_on=False, transform=ax.transData)
return cb_patch
import imageio
im = imageio.imread(pic_dir + 'sample_heatmap.png')
fig, ax = plt.subplots()
ax.imshow(im)
bands = np.array([0, 175, 320, 448, 585, 610, 815])
bnames = ['H3K4me3', 'H3K9me3', 'H3K27me3', 'H3K36me3', 'CTCF', 'H3K4me1']
for y, h, bn in zip(bands, np.diff(bands), bnames):
cb = CurlyBrace([990, y+h*0.025], 30, h*.95)
ax.add_patch(cb)
ax.text(1030, y+h/2, bn, va='center')
plt.tight_layout(rect=[0.05, 0, 0.85, 1])
结果:
【讨论】: