0

我正在处理broken_barh 图。有什么办法可以得到一个固定的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 个破碎的酒吧 http://imageshack.us/a/img195/747/brokenbarhexample2.png

有 3 个破碎的酒吧 http://img341.imageshack.us/img341/5650/brokenbarhexamplenoyran.png

4

1 回答 1

1

渲染适合所有可用空间。如果您希望图形的大小随着添加更多行而增长,您可以通过以下方式手动完成

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

强制固定条形高度。

(文档)

于 2013-02-02T20:55:59.080 回答