def bar_chart_generator():
l = [1,2,3,4,5]
h = [20, 14, 38, 27, 9]
w = [0.1, 0.2, 0.3, 0.4, 0.5]
b = [1,2,3,4,5]
fig = plt.figure()
ax = fig.add_subplot(111)
rects = ax.bar(l, h, w, b,
color='#ffff00',
edgecolor='#000000',
linewidth=2,
#xerr=4,
#yerr=1,
#ecolor='#999999',
#capsize=10,
#align='center',
#orientation='horizontal',
)
plt.savefig('bar.png')
函數原型:
matplotlib.pyplot.bar(left, height, width=0.8, bottom=None, hold=None, **kwargs)
基本參數:
left 每一個柱x軸左邊界
bottom 每一個柱y軸下邊界
height 柱高度(Y軸方向)
width 柱寬度(X軸方向)
以上參數能夠設置爲數值或者list
但要保證若是爲list, len(list)要一致
繪製的方形爲:
X: left --- left+width
Y: bottom --- bottom+height
返回值:
matplotlib.patches.Rectangle
柱狀圖使用bottom擴展便可化爲甘特圖 Gantt Chart
其餘參數:
color Bar顏色
edgecolor Bar邊界線顏色
align 可選['left'(default) | 'center']
決定整個bar圖分佈
默認left表示默認從左邊界開始繪製,center會將圖繪製在中間位置
xerr x方向error bar
yerr y方向error bar
ecolor error bar顏色
capsize error bar橫線寬度(default 3)
樣例:
基本設置
l = [1,2,3,4,5]
h = [20, 14, 38, 27, 9]
w = [0.1, 0.2, 0.3, 0.4, 0.5]
b = [1,2,3,4,5]
設置xerr=4
設置yerr=1,ecolor='#999999'
轉載至 http://blog.sina.com.cn/s/blog_b09d4602010194wy.html