直接上代码
import numpy as np
import matplotlib.pyplot as plt
from pylab import *
import matplotlib; matplotlib.use('TkAgg')
mpl.rcParams['font.sans-serif'] = ['SimHei']
mpl.rcParams['axes.unicode_minus'] = False
Pstate1 = np.array([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0]])
for i in range(24 - 1):#遍历每一个时间
#机组1
if Pstate1[0,i]*Pstate1[0,i+1]==1:
plt.plot([i, i + 1], [Pstate1[0,i], Pstate1[0,i+1]], color='red')
elif Pstate1[0,i]*Pstate1[0,i+1]!=1:
plt.plot([i, i + 1], [Pstate1[0, i], Pstate1[0, i + 1]], color='white')
#机组2
if Pstate1[1, i] * Pstate1[1, i + 1] == 1:
plt.plot([i, i + 1], 2*np.array([Pstate1[1, i], Pstate1[1, i + 1]]), color='blue')
elif Pstate1[1, i] * Pstate1[1, i + 1] != 1:
plt.plot([i, i + 1], 2*np.array([Pstate1[1, i], Pstate1[1, i + 1]]), color='white')
#机组3
if Pstate1[2, i] * Pstate1[2, i + 1] == 1:
plt.plot([i, i + 1], 3*np.array([Pstate1[2, i], Pstate1[2, i + 1]]), color='deeppink')
elif Pstate1[2, i] * Pstate1[2, i + 1] != 1:
plt.plot([i, i + 1], 3*np.array([Pstate1[2, i], Pstate1[2, i + 1]]), color='white')
# 机组4
if Pstate1[3, i] * Pstate1[3, i + 1] == 1:
plt.plot([i, i + 1], 4 * np.array([Pstate1[3, i], Pstate1[3, i + 1]]), color='burlywood')
elif Pstate1[3, i] * Pstate1[3, i + 1] != 1:
plt.plot([i, i + 1], 4 * np.array([Pstate1[3, i], Pstate1[3, i + 1]]), color='white')
#机组5
if Pstate1[4, i] * Pstate1[4, i + 1] == 1:
plt.plot([i, i + 1], 5 * np.array([Pstate1[4, i], Pstate1[4, i + 1]]), color='darkgreen')
elif Pstate1[4, i] * Pstate1[4, i + 1] != 1:
plt.plot([i, i + 1], 5 * np.array([Pstate1[4, i], Pstate1[4, i + 1]]), color='white')
#机组6
if Pstate1[5, i] * Pstate1[5, i + 1] == 1:
plt.plot([i, i + 1], 6 * np.array([Pstate1[5, i], Pstate1[5, i + 1]]), color='crimson')
elif Pstate1[5, i] * Pstate1[5, i + 1] != 1:
plt.plot([i, i + 1], 6 * np.array([Pstate1[5, i], Pstate1[5, i + 1]]), color='white')
plt.yticks([0,1,2,3,4,5,6], labels=[' ','机组1','机组2','机组3','机组4','机组5','机组6'])
plt.xticks(np.arange(0,24,1))
plt.xlabel('t/h')
plt.title('方法一机组开停状态组合')
plt.show()
![](https://i-blog.csdnimg.cn/blog_migrate/e67448dc628d3e0601b2f8bb6597d1fa.png#pic_center)
作者:电气-余登武