簡體   English   中英

Matplotlib package 安裝了,代碼不起作用

[英]Matplotlib package is installed, and the code is not working

代碼不工作,但在網站“repl.it”它工作,沒有任何反應。 fig.show() 應該打印一個圖表。

import matplotlib.pyplot as plt

seq_human = {'AA': 116, 'AT': 95, 'AC': 97, 'AG': 113, 'TA': 85, 'TT': 113, 'TC': 109, 'TG': 111, 'CA': 87, 'CT': 105, 'CC': 184, 'CG': 170, 'GA': 134, 'GT': 105, 'GC': 155, 'GG': 184}
seq_bacteria = {'AA': 105, 'AT': 64, 'AC': 86, 'AG': 111, 'TA': 64, 'TT': 57, 'TC': 60, 'TG': 108, 'CA': 83, 'CT': 75, 'CC': 74, 'CG': 97, 'GA': 113, 'GT': 93, 'GC': 109, 'GG': 147}


fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(16, 5))

ax1.bar(seq_human.keys(), seq_human.values(), width=0.4, align='edge', label='Human: 18S rRNA gene')
ax1.bar(seq_bacteria.keys(), seq_bacteria.values(), width=-0.4, align='edge', label='Bacteria: Escherichia coli 16S ribosomal')
ax1.set_ylabel('Frequency')
ax1.set_xlabel('Nitrogenous Bases')
ax1.legend()
fig.show()

來自fig.show的文檔字符串

警告:

這不管理 GUI 事件循環。 因此,如果您或您的環境未管理事件循環,則該圖可能僅顯示簡短或根本不顯示。

.Figure.show的正確用例包括從 GUI 應用程序或 IPython shell 運行它。

If you're running a pure python shell or executing a non-GUI python script, you should use matplotlib.pyplot.show instead , which takes care of managing the event loop for you.

重點是我的……

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM