pycharm python pyqt5

为什么一样的程序 我出的图和答案的不一样呢

img



import matplotlib.pyplot as plt
import numpy as np
class yunxingtu():
    def __init__(self):
        self.start_time_down = 600  # 十点
        self.start_time_up = 610  # 10:10

        # 各个站点往返时间(单位分钟)
        self.t_interval = 10
        # 各个站点位置
        self.station_A = 0  # 东环校区站
        self.station_B = 15  # 三门江站
        self.station_C = 20  # 会展中心站
        self.station_D = 30  # 柳东校区站# 要绘制的时间段

        self.plt_time_long = self.start_time_down + 60  # 绘制一个小时
        self.interval = 10  # 每10分钟绘制一次
        self.station_run_down = [self.station_A, self.station_B, self.station_C, self.station_D]  # 下行
        self.station_run_up = [self.station_D, self.station_C, self.station_B, self.station_A]  # 上行

    def runOnce(self, station_run, color):
        time_and_position = []
        for i in range(len(station_run)):  # 遍历所有车站
            t_i = i * self.t_interval  # 每两个站间运行时间相同, # 求出从始发站到每个站所用时间
            station_temp = station_run[i]
            time_and_position.append([t_i, station_temp])
# 后面根据每个发车时刻,分别求其每个发车时刻对应的,列车行驶循环中实际时间与位置对照表
    # 并在两两相邻站点画直线,行车运行图
        time_and_position = np.array(time_and_position)

        if station_run[0]==self.station_A:
            t_temp=self.start_time_down
        else:
            t_temp=self.start_time_up   #否则记录上行始发时刻

        t_real = t_temp+ time_and_position[:, 0]   #将始发时刻与每个站点#对应的时间相加得实际时刻
        position_real = time_and_position[:, 1]    #记录实际位置
# 对相邻先后顺序站点两两的时间、位置坐标,画线
        for i in range(len(t_real) - 1):
            point1_t = t_real[i]         #第一各点的实际时刻
            point1_p = position_real[i]  #第一个点的实际站点位置
            point2_t = t_real[i + 1]    #第二个点的实际时刻
            point2_p = position_real[i + 1]  #第二个点的站点位置
            plt.plot([point1_t, point2_t], [point1_p, point2_p], color) #连线得两个站点的运行线
        if station_run[0] == self.station_A:  # 若为下行,则车次号为L01
            plt.text(t_real[0]+2, position_real[0]+2, 'L01',color=color)
        else:
            plt.text(t_real[0] + 2, position_real[0]-2, 'L02', color=color)#否则车次号为L02

    def Draw_Floor (self):
        for i in range(self.start_time_down,self.plt_time_long,self.interval):
            plt.plot([i, i], [self.station_run_down[0], self.station_run_down[-1]], '--g')

        for station in self.station_run_down:
            plt.plot([self.start_time_down,self.plt_time_long,], [station,station], '--g')

# X轴标注
    label_X = ['10:00', '10:10', '10:20', '10:30', '10:40', '10:50']
    plt.xticks(range(600, 660, 10), labels=label_X, rotation=30)
# Y轴标注
    label_y = ['dongH', 'sanMJ', 'huiZZX', 'liuD']
    range_y = [0, 15, 20, 30]
    plt.yticks(range_y, labels=label_y)

    plt.xlabel('time(hour:min)')
    plt.ylabel('station')
    plt.title('railway')
    plt.show()


if __name__ == "__main__":
    a = yunxingtu()

    a.runOnce(a.station_run_up, 'r')
    a.runOnce(a.station_run_down,'b')

    a.Draw_Floor()

img