I am trying to plot certain discrete scores based on a timestamp at which they were recorded. There are 4 separate dataframes(pandas) called lower-back-Now, lower-back-Worst, Neck-Now, and Neck-Worst. And also, at some particular days offset from the initial timestamp index I plot axvlines to denote some interventions with text. The dataframes look like these..
lbNow
Answer
StartUnixTime
1970-01-01 16:45:55 4
1970-01-01 19:30:53 5
1970-01-02 05:00:11 6
1970-01-02 19:31:01 3
1970-01-03 05:06:29 5
lbWst
Answer
StartUnixTime
1970-01-01 16:46:08 6
1970-01-01 19:30:53 5
1970-01-02 05:00:18 6
1970-01-02 19:31:10 7
1970-01-03 05:06:29 5
neckNow
Answer
StartUnixTime
1970-01-01 16:46:26 4
1970-01-01 19:31:39 6
1970-01-02 05:00:27 6
1970-01-02 19:31:17 2
1970-01-03 05:07:04 4
neckWst
Answer
StartUnixTime
1970-01-01 16:46:31 5
1970-01-01 19:31:47 6
1970-01-02 05:00:28 6
1970-01-02 19:31:22 7
1970-01-03 05:07:08 4
and the code for the plot for plottin using matplotlib in subplots is as follows:
fig = plt.figure(figsize=(15,15))
ax1 = fig.add_subplot(211)
myfmt = mdates.DateFormatter('%m-%d')
ax1.plot(lbNow,color='#055F65',label='Lower Back Now')
ax1.plot(lbWst,color='#c50d63',label='Lower Back worst',linestyle='--')
ax1.xaxis.set_major_formatter(myfmt)
for label in ax1.xaxis.get_ticklabels():
label.set_rotation(45)
# fig.autofmt_xdate()
ax1.legend(loc='best')
ax1.set(title='Lower Back Pain Dairy',xlabel='Timestamps since start date',ylabel='Pain Scores')
ax1.axvline(x=lbNow.index[0] + pd.DateOffset(days=1),color = 'r',linestyle='-.')
ax1.text(lbNow.index[0] + pd.DateOffset(days=2),8.1,'MBB#1',rotation=45)
ax1.axvline(x=lbNow.index[0] + pd.DateOffset(days=22),color = 'b',linestyle='-.')
ax1.text(lbNow.index[0] + pd.DateOffset(days=23),8.1,'MBB#2',rotation=45)
ax1.axvline(x=lbNow.index[0] + pd.DateOffset(days=43),color = 'k',linestyle='-.')
ax1.text(lbNow.index[0] + pd.DateOffset(days=44),8.1,'RFA',rotation=45)
# ax1.set_ylim((0,10))
ax1.grid(True)
ax3 = fig.add_subplot(212)
ax3.plot(neckNow,color='#4b0d2b',label='Neck Now',linestyle='-')
ax3.plot(neckWst,color='#c50d63',label='Neck Worst',linestyle='--')
ax3.xaxis.set_major_formatter(myfmt)
for label in ax3.xaxis.get_ticklabels():
label.set_rotation(45)
fig.autofmt_xdate()
ax3.legend(loc='lower center')
ax3.set(title='Neck Pain Dairy',xlabel='Timestamps since start date', ylabel='Pain Scores')
ax3.axvline(x=neckNow.index[0] + pd.DateOffset(days=1),color = 'r',linestyle='-.',clip_on=False)
ax3.text(neckNow.index[0] + pd.DateOffset(days=2),8,'MBB#1',rotation=45)
ax3.axvline(x=neckNow.index[0] + pd.DateOffset(days=22),color = 'b',linestyle='-.')
ax3.text(neckNow.index[0] + pd.DateOffset(days=23),8,'MBB#2',rotation=45)
ax3.axvline(x=neckNow.index[0] + pd.DateOffset(days=43),color = 'k',linestyle='-.')
ax3.text(neckNow.index[0] + pd.DateOffset(days=44),8,'RFA',rotation=45)
ax3.grid(True)
fig.tight_layout()
plt.show()
The problem is with the second subplot with neckNow and neckWst plotting. If I plot both df then the ax3.axvline do not appear as shown
But then if Comment the neckNow plot then the lines appear as shown.
Is there any problem with the y limits or is the timestamp causing this weird error ?