I am trying to plot a Gantt chart. I am new to python and not familiar with advanced programming concepts. On running the code I get the error shown.
import numpy as np
import matplotlib as mpl
import pylab as plt
arr=np.loadtxt('gantt.csv',dtype=float,delimiter=",")
colormapd = {
1:"r",
2:"g",
3:"b",
4:"y",
5:"m",
6:"k",
7:"r",
8:"g",
9:"b",
0:"y",
}
therange=range(500,2500)
jobnum= arr[therange,0].astype(int)
macnum= arr[therange,2].astype(int)
procstart = arr[therange,3]
procfinish = arr[therange,4]
for i in range(500,2500):
plt.hlines(macnum[i],procstart[i],procfinish[i],colors = colormapd[1])
plt.show()
Error:
IndexError: index 2000 is out of bounds for axis 0 with size 2000
I think what I need is to be able to vectorize (jobnum%10) the array used to access the dictionary.
plt.hlines(macnum,procstart,procfinish,colors = colormapd[jobnum%10])
I am able to run:
plt.hlines(macnum,procstart,procfinish)
But I wish to change colors of lines as per the jobnumbers. I have 2500+ jobs. Any other method to create gantt chart, if better could be suggested too.