是否有任何关于如何正确绘制它以零开始Y栏的建议?
使用这本词典:
D = {
'GCF_000416945.1': '450',
'GCF_001294115.1': '451',
'GCF_000245395.1': '416',
'GCF_002318825.1': '451',
'GCF_001401215.1': '450',
'GCF_000935735.1': '450'
}
和这些行:
plt.bar(range(len(D)), D.values(), align='center') # python 2.x
plt.xticks(range(len(D)), D.keys())
答案 0 :(得分:1)
您需要将所有字典值转换为整数,因为将使用当前代码引发错误TypeError: unsupported operand type(s) for +: 'int' and 'str'
。当纠正后一个错误时,代码在Python2中实现了正确的结果:
import matplotlib.pyplot as plt
D = {
'GCF_000416945.1': '450',
'GCF_001294115.1': '451',
'GCF_000245395.1': '416',
'GCF_002318825.1': '451',
'GCF_001401215.1': '450',
'GCF_000935735.1': '450'
}
plt.bar(range(len(D)), map(int, D.values()), align='center')
plt.xticks(range(len(D)), D.keys())
答案 1 :(得分:0)
以下行应该可以解决问题:
plt.ylim(ymin=0)