Reputation: 73
I am trying to plot a time series with a break of about one year in the middle. I attempted to essentially make 2 subplots sharing a y-axis, with a break between two x limits. However, the first plot (the first period of the time series, before the break) doesn't show up. Any suggestions?
import matplotlib.dates as mdates
os.chdir(r'C:\Users\work\Documents\DavisData\graphs\2020')
for c in relevant_categories:
if subset_m[c].sum() > 0:
# plt.figure(figsize=(12,10))
f,(ax,ax2) = plt.subplots(1,2,sharey=True, facecolor='w')
ax = subset_m[c].plot(color='tomato', grid = False, label='Davis Topics')
ax2 = subset_m[c].plot(color='tomato', grid = False, label='Davis Topics')
### make the break
ax.set_xlim([datetime.date(2010, 1, 1), datetime.date(2017, 12, 30)])
ax2.set_xlim([datetime.date(2019, 1, 1), datetime.date(2020, 7, 1)])
# hide the spines between ax and ax2
ax.spines['right'].set_visible(False)
ax2.spines['left'].set_visible(False)
ax.yaxis.tick_left()
ax.tick_params(labelright='off')
ax2.yaxis.tick_right()
plt.show()
Unfortunately, this is the graph I receive:
Upvotes: 0
Views: 114
Reputation: 81
ax = subset_m[c].plot(color='tomato', grid = False, label='Davis Topics')
ax2 = subset_m[c].plot(color='tomato', grid = False, label='Davis Topics')
should be
subset_m[c].plot(color='tomato', grid = False, label='Davis Topics', ax=ax)
subset_m[c].plot(color='tomato', grid = False, label='Davis Topics', ax=ax2)
Upvotes: 3