我能够用下面的代码生成以下情节:
df_day['Time'] = pd.to_datetime(df_day['Time'], format = '%H:%M:%S')
df_day = df_day.set_index('Time')
fig=plt.figure(dpi=900)
plt.title("TESTER Summary for Day %i " %y + "\n Average Chamber Pressure %.3f [torr] \n" %p_avg_temp + str(dates[x]))
ax1 = df_day['DP-2'].plot(label = 'DP-2')
ax2 = df_day['FM-1'].plot(secondary_y = True, label = "Flow Rate")
ax1.set_ylabel('Temperatures - Pressure Drop\nInlet Pressure - Scale Weight')
ax2.set_ylabel('Flow Rate - Heat Rej.')
ax1.set_xlabel('Time ')
handles,labels = [],[]
for ax in fig.axes:
for h,l in zip(*ax.get_legend_handles_labels()):
handles.append(h)
labels.append(l)
plt.legend(handles, labels, loc = 'lower center', bbox_to_anchor = (0.5, -0.5), ncol = 3)
fig.subplots_adjust(bottom = 0.25)
ax1.grid(True, linestyle = ':')
ax2.grid(True, linestyle = ':')
plt.show()

但我不想让日期出现在xtick标签上。我要几个小时,几分钟,几秒。我也尝试过:
df_day['Time'] = pd.Series([val.time() for val in df_day['Time']])而不是
df_day['Time'] = pd.to_datetime(df_day['Time'], format = '%H:%M:%S')但后来我得到了

时间间隔是任意的,不包括秒数为00的秒。
发布于 2022-01-11 14:09:32
在编写代码之前,尝试运行以下行:
import matplotlib.dates as mdates
myFmt = mdates.DateFormatter('%H:%M:%S') # here you can format your datetick labels as desired
plt.gca().xaxis.set_major_formatter(myFmt)https://stackoverflow.com/questions/69111116
复制相似问题