2017-05-03 169 views
0

我想要一個條形圖顯示x值範圍從0-9。 酒吧應該有相同的空間,我遇到的問題是將10個值合在一起,而所有酒吧都有相同的面積空間。Matplotlib條形圖軸值

import matplotlib.pyplot as plt 

fig = plt.figure(figsize=(10, 6)) 
results_plot = plt.subplot2grid((10, 6), (0,0), colspan=8, rowspan=2) 
results_plot.set_title("Results") 

res_x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 
res_y = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100] 

rects = plt.bar(res_x, res_y, color='b') 
results_plot.set_xbound(lower=0.0, upper=9.0) 
results_plot.set_ybound(lower=0.0, upper=100.0) 


results_plot2 = plt.subplot2grid((10, 6), (3,0), colspan=8, rowspan=2) 
results_plot2.set_title("Results 2") 

res_x2 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 
res_y2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100] 

rects2 = plt.bar(res_x2, res_y2, color='b') 
results_plot2.set_xbound(lower=-.5, upper=9.5) 
results_plot2.set_ybound(lower=0.0, upper=100.0) 

plt.show() 

enter image description here

因此,在短期我想看到的軸的所有的x值(例如在圖1)的每一個具有相同的條間隔(圖2)。

回答

2

如果您只想在每個欄下面打勾,可以使用您的res_x直接設置xticks。地址:

results_plot2.set_xticks(res_x) 

enter image description here

+0

正是我一直在尋找,TY。 – dtam