我有從SQL數據庫查詢派生直方圖。的代碼如下:matplotlib直方圖軸格式化
def histogram(self):
conn = sqlite3.connect('tooldatabase.db')
c = conn.cursor()
c.execute('PRAGMA foreign_keys = ON')
c.execute("SELECT evaluation from evaluations")
evaluations=c.fetchall()
print(evaluations)
minimum=min(evaluations, key = lambda t: t[0])
maximum=max(evaluations, key = lambda t: t[0])
print(minimum,maximum)
eval=[]
for (y,) in evaluations:
eval.append(y)
bin=[]
for x in range(1,maximum[0]+2):
bin.append(x)
figure=plt.figure(1)
plt.hist(eval,bins=bin, facecolor='blue',edgecolor='black',)
plt.xticks(bin, bin)
plt.xlabel('evaluation')
plt.ylabel('No of problems')
plt.title('Evaluations Distribution Histogram')
plt.show()
的輸出如下所示: https://gyazo.com/d73b20a118db0088aab261c079613b00
我想將其顯示爲: https://gyazo.com/063990cd8741682f45b5a37ba594ff56
當x軸的數字是向右偏移側多一點。有沒有辦法做到這一點?
的可能的複製[Matplotlib xticks不排隊與直方圖(http://stackoverflow.com/questions/27083051/ – DavidG