2013-02-02 60 views
0

我正在使用broken_barh圖。有沒有辦法獲得單個broken_barh的固定高度?圖像應垂直放大,但比例應保持不變。Matplotlib:具有相同高度的Broken_barh圖

這是一個簡單的例子。

import matplotlib.pyplot as plt 
import matplotlib as mlp 

fig = plt.figure() 
ax = fig.add_subplot(111) 

broken_barh(self, xranges, yrange, **kwargs) 
ax.broken_barh([(110, 30), (150, 10)], (0, 10), facecolors='blue') 
ax.broken_barh([(10, 50), (100, 20), (130, 10)] , (10, 10), 
       facecolors=('red', 'yellow', 'green')) 
ax.broken_barh([(50, 30), (85, 10)], (20, 10), facecolors='black') 

ax.set_xlim(0,200) 
ax.set_xlabel('seconds since start') 
ax.set_yticks([0,10,20]) 
ax.set_yticklabels(['Bill', 'Jim', 'Jeff']) 
ax.grid(True) 

plt.savefig('broken_barh_example.png', bbox_inches='tight') 
plt.show() 

如果我生成兩個地塊,一個有兩個broken_barh和其他三個,它看起來像這樣:

2 broken_barh http://imageshack.us/a/img195/747/brokenbarhexample2.png

3 broken_barh http://img341.imageshack.us/img341/5650/brokenbarhexamplenoyran.png

回答

1

渲染適合所有可用空間。如果你想圖的尺寸爲你添加更多的行成長,你可以通過

fig.set_size_inches(w, h * num_rows, forward=True) 

手工做強制固定杆高度。

(doc)

+0

thx,完美的作品! – jackson

相關問題