python matplotlib plt 画图 将刻度 替换为文字/字符以及画断断续续的分段函数

直接上代码

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()

在这里插入图片描述
作者:电气-余登武

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

总裁余(余登武)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值