Python 未显示的绘图
目的是创造一个情节。我有以下脚本:Python 未显示的绘图,python,plot,Python,Plot,目的是创造一个情节。我有以下脚本: #!/usr/bin/python import sys from matplotlib import pyplot as plt from matplotlib.collections import BrokenBarHCollection file = sys.argv[1] color_lookup = { 'INS': (1., 1., 1.), 'DEL': (.6, .6, .6), 'DUP': (.4, .4, .4),
#!/usr/bin/python
import sys
from matplotlib import pyplot as plt
from matplotlib.collections import BrokenBarHCollection
file = sys.argv[1]
color_lookup = {
'INS': (1., 1., 1.),
'DEL': (.6, .6, .6),
'DUP': (.4, .4, .4),
'INV': (.2, .2, .2),
'TRA': (0., 0., 0.),
}
height = 0.9
spacing = 0.9
def ideograms(fn):
last_chrom = None
fin = open(fn)
fin.readline()
xranges, colors = [], []
ymin = 0
print "Reading input..."
for line in fin:
chrom, start, stop, label = line.strip().split('\t')
start = int(start)
stop = int(stop)
width = stop - start
if chrom == last_chrom or (last_chrom is None):
xranges.append((start, width))
colors.append(color_lookup[label])
last_chrom = chrom
continue
ymin += height + spacing
yrange = (ymin, height)
yield xranges, yrange, colors, last_chrom
xranges, colors = [], []
xranges.append((start, width))
colors.append(color_lookup[label])
last_chrom = chrom
# last one
ymin += height + spacing
yrange = (ymin, height)
yield xranges, yrange, colors, last_chrom
fig = plt.figure()
ax = fig.add_subplot(111)
d = {}
yticks = []
yticklabels = []
# ideogram.txt downloaded from UCSC's table browser
for xranges, yrange, colors, label in ideograms(file):
coll = BrokenBarHCollection(xranges, yrange, facecolors=colors)
ax.add_collection(coll)
center = yrange[0] + yrange[1]/2.
yticks.append(center)
yticklabels.append(label)
d[label] = xranges
ax.axis('tight')
ax.set_yticks(yticks)
ax.set_yticklabels(yticklabels)
ax.set_xticks([])
fig.show()
它采用以下文本文件:
15_dna:chromosome_chromosome:Sscrofa10.2:15:1:157681621:1_REF 1020262 1021297 INV
15_dna:chromosome_chromosome:Sscrofa10.2:15:1:157681621:1_REF 3997094 3997771 INV
15_dna:chromosome_chromosome:Sscrofa10.2:15:1:157681621:1_REF 7554794 7555726 INV
15_dna:chromosome_chromosome:Sscrofa10.2:15:1:157681621:1_REF 12102772 12127279 INV
15_dna:chromosome_chromosome:Sscrofa10.2:15:1:157681621:1_REF 12222645 12256683 INV
15_dna:chromosome_chromosome:Sscrofa10.2:15:1:157681621:1_REF 12641052 12642314 INV
15_dna:chromosome_chromosome:Sscrofa10.2:15:1:157681621:1_REF 12852136 12854980 INV
15_dna:chromosome_chromosome:Sscrofa10.2:15:1:157681621:1_REF 13049643 13113925 INV
15_dna:chromosome_chromosome:Sscrofa10.2:15:1:157681621:1_REF 13199758 13206459 INV
但是脚本不会输出任何绘图,也不会给出错误。你知道发生了什么事吗
编辑:我刚刚删除了center=yrange[0]+yrange[1]/2之后的那一点。
现在它抛出了以下错误/home/software/002解释器/lib/python2.7/site packages/matplotlib/figure.py:387:UserWarning:matplotlib当前正在使用非GUI后端,因此无法显示该图
“matplotlib当前使用的是非GUI后端,”
您必须调用plt.show()
,不是吗?我已经通过fig.show()调用了这个函数。
运行此函数时,我得到了一个绘图(虽然只有一行要绘图,但我认为您需要重新考虑您的产量逻辑)。。。也许可以检查你的后端设置?啊,(刚刚看到更新)好了,你去吧…我怎么解决这个问题?