答案1
很难知道到底发生了什么,但据我所知,这将解决你的问题
import matplotlib.pyplot as plt
import datetime
from matplotlib2tikz import save as tikz_save
# input data
t = ['10:00:00', '10:05:00', '10:07:00', '10:27:00']
P = [10, 20, 30, 40]
plt.style.use('ggplot')
fmt = '%H:%M:%S'
tseconds = [datetime.datetime.strptime(k, fmt) for k in t]
dt = [(k - tseconds[0]).seconds for k in tseconds]
dtmax = float(max(dt))
dt = np.array(dt) / dtmax
fig, ax = plt.subplots()
ax.plot(dt, P)
ax.set_xlabel('time')
ax.set_ylabel('Pressure')
fig.canvas.draw()
labels = plt.xticks()
labels = [datetime.timedelta(seconds = label * dtmax) + tseconds[0] for label in labels[0]]
tlabels = [label.strftime(fmt) for label in labels]
ax.set_xticklabels(tlabels)
plt.xticks(rotation = 45)
# export
tikz_save('test.tex')
我知道x
-label 不对,我会把那部分留给你去弄清楚