【发布时间】:2017-11-09 00:56:54
【问题描述】:
我的目标是用条形图表示分配的时间。分配的小时数应表示为 sched_hrs 上方的 tot_hrs。因此,7 处的线应该在 'Blairstone FL' 处的 1 条的正上方。然而,情节出现在“Blairstone FL”、“Bonifay FL”和“Calhoun FL”之上的三行 7、8 和 9。主要问题存在于 tt in range(len(service_areas)): 中的以下代码。非常感谢任何帮助。
sched_hrs=[1, 2, 3]
tot_hrs=[7, 8, 9]
columnstart = -0.5
columnend = 0.5
service_areas = ['Blairstone FL', 'Bonifay FL', 'Calhoun FL']
plt.figure(figsize=(len(service_areas) + 4.5, 4)).canvas.set_window_title('Click')
ind = np.arange(len(service_areas))
width = 0.18
plt.bar(ind, sched_hrs,width, label='Scheduled Hours', color='green', align="center")
for tt in range(len(service_areas)):
plt.plot([columnstart, columnend], [tot_hrs, tot_hrs], color='#228B22', linestyle='-', linewidth=2)
columnstart +=1
columnend +=1
plt.xticks(ind, service_areas, rotation=10)
plt.yticks(np.arange(0, max(1, max(tot_hrs) + 2), 1))
plt.title("Allocated Hours")
plt.xlabel("Areas")
plt.ylabel("Hours")
plt.legend()
plt.show()
【问题讨论】:
-
所以基本上你想创建一个堆积条形图,每个条形图由 sched_hrs 和 tot_hrs 组成?
-
不是堆积图。我想在条形图上方有一个折线图。不过谢谢。
标签: python python-3.x matplotlib bar-chart