Reputation: 653
Any suggestion of how to plot it correctly starting the Y bar with a zero?
using this dictionary:
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'
}
and these lines:
plt.bar(range(len(D)), D.values(), align='center') # python 2.x
plt.xticks(range(len(D)), D.keys())
Upvotes: 1
Views: 89
Reputation: 71461
You need to convert all your dictionary values to integers as an error TypeError: unsupported operand type(s) for +: 'int' and 'str'
will be raised with the current code. When the latter error is corrected, the code achieves the correct result in 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())
Upvotes: 1
Reputation: 39860
The following line should do the trick:
plt.ylim(ymin=0)
Upvotes: 0