阿波罗的战车
您可以通过在绘制数组之前对数组进行子设置来节省大量内存:import datetimeimport matplotlib.pyplot as pltimport matplotlib.dates as mdatesimport numpy as npn_times = 24 * 60 * 60 * 100times = [ datetime.datetime(2018, 12, 22,00,00) + datetime.timedelta(milliseconds=10 * x) for x in range(n_times)]tiempo2 = np.array(times)valores2 = np.random.normal(size=n_times)#Franja de 0 a 4franja1=plt.subplot(611)index = np.logical_and(tiempo2 >= datetime.datetime(2018, 12, 22, 0, 0), tiempo2 < datetime.datetime(2018, 12, 22, 4, 0, 0))franja1.plot(tiempo2[index], valores2[index], lw=0.2,color='red')#Franja de 4 a 8franja2=plt.subplot(612)index = np.logical_and(tiempo2 >= datetime.datetime(2018, 12, 22, 4, 0), tiempo2 < datetime.datetime(2018, 12, 22, 8, 0, 0))franja2.plot(tiempo2[index], valores2[index], lw=0.2,color='green')#Franja de 8 a 12franja3=plt.subplot(613)index = np.logical_and(tiempo2 >= datetime.datetime(2018, 12, 22, 8, 0), tiempo2 < datetime.datetime(2018, 12, 22, 12, 0, 0))franja3.plot(tiempo2[index], valores2[index], lw=0.2,color='blue')#Franja de 12 a 16franja4=plt.subplot(614)index = np.logical_and(tiempo2 >= datetime.datetime(2018, 12, 22, 12, 0), tiempo2 < datetime.datetime(2018, 12, 22, 16, 0, 0))franja4.plot(tiempo2[index], valores2[index], lw=0.2,color='red')#franja de 16 a 20franja5=plt.subplot(615)index = np.logical_and(tiempo2 >= datetime.datetime(2018, 12, 22, 16, 0), tiempo2 < datetime.datetime(2018, 12, 22, 20, 0, 0))franja5.plot(tiempo2[index], valores2[index], lw=0.2,color='green')#Franja de 20 a 24franja6=plt.subplot(616)index = np.logical_and(tiempo2 >= datetime.datetime(2018, 12, 22, 20, 0), tiempo2 < datetime.datetime(2018, 12, 23, 0, 0, 0))franja6.plot(tiempo2[index], valores2[index], lw=0.2,color='blue')franja1.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))franja2.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))franja3.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))franja4.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))franja5.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))franja6.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))plt.show()