'Matplotlib horizontal barh graph not displaying correctly within ranges. How to make a gnat style chart
I'm not sure what I'm supposed to do to make this kind of thing work. I need something that will display my bar graphs like a gant chat. Each bar should show right after the next one. Notice how it only works for the first one. What can I do to make it work like I would expect. Where each bar is drawn at the correct time and ends at the correct time.
plt.rcdefaults()
fig, ax = plt.subplots()
people = [0,1,2,3,4]
peopleStr = [str(i) for i in people]
y_pos = np.arange(len(people))
target_bars_start = [0.00, 10.0, 30.0, 40.0, 50.0]
target_bars_end = [10.0, 30.0, 40.0, 50.0, 70.0]
target_bars_start2 = [5.00, 13.0, 32.0, 40.0, 45.0]
target_bars_end2 = [13.0, 32.0, 40.0, 45.0, 60.0]
plt.barh(y_pos, left=target_bars_start, width=target_bars_end,height=0.10,color="green", label="Time 1")
#plt.barh(y_pos+0.2, left=target_bars_start2, width=target_bars_end2,height=0.10,color="red", label="Time 2")
ax.set_yticks(y_pos, labels=peopleStr)
ax.invert_yaxis()
ax.set_ylabel('Person')
ax.set_xlabel('Completion time')
fig.tight_layout()
plt.legend()
plt.show()
What I expect is that bar is drawn right after the other one.Again for sime reason it only works on the first 2. 0 and 1. The rest do not display correctly. Notice the second one is not even stopping at 30 but bleeds into like 41.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

