2013-10-21 30 views
1

我正在尋找一種簡單的方法(如果可能的話)來表示一系列任務在cpu上的調度,如幻燈片5 here用matplotlib調度算法的可視化

我想要爲每個任務設置不同的線條,我可以在其上表示到達時間,截止日期等等。我想用matplotlib來做,但目前我不知道這是一個簡單的方法。

回答

1

我會先檢查matplotlib gallery以查看類似的情節。這裏subplot似乎是合適的,因此可以從this之類的東西開始。 正如你想刪除一些刺(軸),你可以進一步檢查this example

要獲得填充塊,我將使用標準的fill_betweenfill調用各自的數據點,請參閱this example

一個簡單的例子是:

import matplotlib.pyplot as plt 

cpu1_t = [0,1,1,3,3,4,5] 
cpu1_p = [1,1,0,0,1,1,0] 
cpu2_t = [0,1,1,3,3,4,5] 
cpu2_p = [0,0,1,1,0,0,1] 

fig = plt.figure() 
# plot 1 
ax1 = fig.add_subplot(211) 
ax1.fill_between(cpu1_t, cpu1_p,0, color='b', edgecolor='k') 
ax1.set_ylabel(r'$\tau_1$', size=14, rotation=0) 
# plot 2 
ax2 = fig.add_subplot(212) 
ax2.fill_between(cpu2_t, cpu2_p,0, color='r', edgecolor='k') 
ax2.set_ylabel(r'$\tau_2$', size=14, rotation=0) 

# customize axis 
for ax in [ax1, ax2]: 
    ax.set_ylim(0,2) 
    ax.spines['right'].set_visible(False) 
    ax.spines['top'].set_visible(False) 
    ax.yaxis.set_ticks_position('left') 
    ax.xaxis.set_ticks_position('bottom') 

enter image description here

可以大,小網格進一步發揮,蜱,等 當然,這僅僅是一種可能的方法來建立這樣一個情節。