python 饼图回溯
python pie chart traceback
我正在尝试在 python 中制作饼图,但我一直收到此回溯。这是我的代码
#!/usr/bin/python
import sys
import re
import matplotlib.pyplot as plt
file1 = open(sys.argv[1])
file2 = open(sys.argv[2])
file3 = open(sys.argv[3])
all = []
count_1 = 0
count_2 = 0
count_3 = 0
for line in file1:
line = line.strip()
if line.startswith(">"):
count_1 += 1
all.append(count_1)
for line in file2:
line = line.strip()
if line.startswith(">"):
if re.search("CAGE_PLUS", line):
count_2 += 1
all.append(count_2)
for line in file3:
line = line.strip()
if line.startswith(">"):
if re.search("known", line):
count_3 += 1
all.append(count_3)
labels = ["All lincRNA", "CAGE lincRNA", "Known lincRNA"]
sizes = all
colors = ['yellowgreen', 'mediumpurple', 'lightskyblue']
plt.pie(sizes, # data
labels=labels, # slice labels
colors=colors, # array of colours
autopct='%1.1f%%' # print the values inside the wedges
)
plt.axis('equal')
plt.savefig('lincRNA_piechart')
我就是这样运行它
python /evolinc_docker/lincRNA_fig.py All.lincRNAs.fa lincRNAs.with.CAGE.support.annotated.fa lincRNAs.overlapping.known.lincs.fa
我得到的回溯是
Traceback (most recent call last):
File "/evolinc_docker/lincRNA_fig.py", line 50, in <module>
plt.pie(sizes, labels=labels, colors=colors)
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 2959, in pie
ax = gca()
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 803, in gca
ax = gcf().gca(**kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 450, in gcf
return figure()
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 423, in figure
**kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 79, in new_figure_manager
return new_figure_manager_given_figure(num, figure)
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 87, in new_figure_manager_given_figure
window = Tk.Tk()
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1767, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable
我运行你的程序有一个简化的所有列表。
import matplotlib.pyplot as plt
labels = ["All lincRNA", "CAGE lincRNA", "Known lincRNA"]
sizes = [10, 20, 30] # my arbitrary list just for testing
colors = ['yellowgreen', 'mediumpurple', 'lightskyblue']
plt.pie(sizes, labels=labels,colors=colors, autopct='%1.1f%%')
plt.axis('equal')
plt.show()
我可以得到下面的情节。所以我认为你的 python 程序很好。但是我检查了 DISPLAY env 变量,它是
$ echo $DISPLAY
/private/tmp/com.apple.launchd.VoooVvQSYh/org.macosforge.xquartz:0
也许您可能需要检查您的 DISPLAY 并正确设置它。
我正在尝试在 python 中制作饼图,但我一直收到此回溯。这是我的代码
#!/usr/bin/python
import sys
import re
import matplotlib.pyplot as plt
file1 = open(sys.argv[1])
file2 = open(sys.argv[2])
file3 = open(sys.argv[3])
all = []
count_1 = 0
count_2 = 0
count_3 = 0
for line in file1:
line = line.strip()
if line.startswith(">"):
count_1 += 1
all.append(count_1)
for line in file2:
line = line.strip()
if line.startswith(">"):
if re.search("CAGE_PLUS", line):
count_2 += 1
all.append(count_2)
for line in file3:
line = line.strip()
if line.startswith(">"):
if re.search("known", line):
count_3 += 1
all.append(count_3)
labels = ["All lincRNA", "CAGE lincRNA", "Known lincRNA"]
sizes = all
colors = ['yellowgreen', 'mediumpurple', 'lightskyblue']
plt.pie(sizes, # data
labels=labels, # slice labels
colors=colors, # array of colours
autopct='%1.1f%%' # print the values inside the wedges
)
plt.axis('equal')
plt.savefig('lincRNA_piechart')
我就是这样运行它
python /evolinc_docker/lincRNA_fig.py All.lincRNAs.fa lincRNAs.with.CAGE.support.annotated.fa lincRNAs.overlapping.known.lincs.fa
我得到的回溯是
Traceback (most recent call last):
File "/evolinc_docker/lincRNA_fig.py", line 50, in <module>
plt.pie(sizes, labels=labels, colors=colors)
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 2959, in pie
ax = gca()
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 803, in gca
ax = gcf().gca(**kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 450, in gcf
return figure()
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 423, in figure
**kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 79, in new_figure_manager
return new_figure_manager_given_figure(num, figure)
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 87, in new_figure_manager_given_figure
window = Tk.Tk()
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1767, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable
我运行你的程序有一个简化的所有列表。
import matplotlib.pyplot as plt
labels = ["All lincRNA", "CAGE lincRNA", "Known lincRNA"]
sizes = [10, 20, 30] # my arbitrary list just for testing
colors = ['yellowgreen', 'mediumpurple', 'lightskyblue']
plt.pie(sizes, labels=labels,colors=colors, autopct='%1.1f%%')
plt.axis('equal')
plt.show()
我可以得到下面的情节。所以我认为你的 python 程序很好。但是我检查了 DISPLAY env 变量,它是
$ echo $DISPLAY
/private/tmp/com.apple.launchd.VoooVvQSYh/org.macosforge.xquartz:0
也许您可能需要检查您的 DISPLAY 并正确设置它。