试图绘制双轴并调整时间戳。不想多个时间戳重叠并且变得难以辨认。关于如何使以下双轴示例正常工作的任何建议?
from matplotlib import pyplot as plt
from matplotlib import dates
from datetime import datetime
import numpy as np
import sys
times = pd.Series(pd.date_range(start='1/1/2018', periods = 3*21, freq='120min'))
values = pd.Series(np.random.randint(0,5, size= 3*21))
other = pd.Series(np.random.randint(0,5, size= 3*21))
data = pd.concat([ times , values, other], axis=1)
data.columns = ['Time','Value', 'Other']
d = data['Time']
t = data['Value']
o = data['Other']
days = dates.DayLocator()
hours = dates.HourLocator()
dfmt = dates.DateFormatter('%b %d %Y')
datemin = min(d).date() # datetime(2018, 1, 1, 0, 0)
datemax = max(d).date() # datetime(2018, 1, 7, 0, 0)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.xaxis.set_major_locator(days)
ax.xaxis.set_major_formatter(dfmt)
ax.xaxis.set_minor_locator(hours)
ax.set_xlim(datemin, datemax)
ax.set_ylabel('Temperature (F)')
plt.xticks(rotation=45)
ax.plot(d, t, linewidth=2)
ax2 = ax1.twinx() # instantiate a second axes that shares the same x-axis
# ax2.set_ylabel('Zscore', color = color)
ax2.plot(d, o)
plt.rcParams.update({'font.size': 12})
plt.show()