-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gantt_Chart.py
50 lines (38 loc) · 1.35 KB
/
Gantt_Chart.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import matplotlib.pyplot as plt
def get_cmap(n, name='hsv'):
'''Returns a function that maps each index in 0, 1, ..., n-1 to a distinct
RGB color; the keyword argument name must be a standard mpl colormap name.'''
return plt.cm.get_cmap(name, n)
def Draw_GanttChart(jobs, total_time):
fig, gnt = plt.subplots()
# Setting Y-axis limits
gnt.set_ylim(0, 4 * len(jobs) + 1)
# Setting X-axis limits
gnt.set_xlim(0, float(total_time))
#gnt.set_xticks(range(0, int(total_time) + 2), 0.1)
xticks = []
for i in range(0, len(jobs)):
for slots in jobs[i]['Time_Slots']:
xticks.append(slots[0])
xticks.append(slots[0] + slots[1])
gnt.set_xticks(xticks)
# Setting labels for x-axis and y-axis
gnt.set_xlabel('Unit Time')
gnt.set_ylabel('Processes')
# Setting ticks on y-axis
# Labelling tickes of y-axis
yticks = []
ylabels = []
for i in range(0, len(jobs)):
yticks.append(3 + (4 * i))
ylabels.append(str(jobs[i]['Task']))
gnt.set_yticks(yticks)
gnt.set_yticklabels(ylabels)
# Setting graph attribute
gnt.grid(True)
cmap = get_cmap(len(jobs) + 1)
for i in range(0, len(jobs)):
gnt.broken_barh(jobs[i]['Time_Slots'], ((2 + (4 * i)), 2), facecolors=cmap(i))
fig.set_size_inches(14, 6)
fig.savefig("fig1.png")
return