2013-10-21 29 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

可以大,小网格进一步发挥,蜱,等 当然,这仅仅是一种可能的方法来建立这样一个情节。