未显示绘图

2024-09-27 09:25:16 发布

您现在位置:Python中文网/ 问答频道 /正文

目的是创造一个情节。我有以下脚本:

#!/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()

它接受以下文本文件:

^{pr2}$

但脚本不输出任何绘图,也不会给出任何错误。你知道发生了什么事吗?在

编辑:我刚刚删除了center = yrange[0] + yrange[1]/2.之后的那一点,现在它抛出以下错误/home/software/002-Interpreters/lib/python2.7/site-packages/matplotlib/figure.py:387: UserWarning: matplotlib is currently using a non-GUI backend, so cannot show the figure "matplotlib is currently using a non-GUI backend, "。在


Tags: matplotlibaxstartlabellaststopcolorsheight

热门问题