Having trouble getting a second (top) x axis labels, ticks plotted when I add a second legend. Minimal code to produce (left plot is what I want, right plot is what I get for the 2nd x axis:
fig, ax = plt.subplots(nrows=1,ncols=2,figsize=(12, 6),sharey=True)
ax[0].plot(range(0,61),range(0,61),label='test')
ax[1].plot(range(0,61),range(0,61),label='test')
ax[0].legend()
ax[0].set_xlim(0,60)
ax[0].set_xticks(range(0,61,6))
axe = ax[0].twiny()
axe.set_xticks(range(0,61,6))
axe.set_xticklabels(['00','06','12','18','00','06','12','18','00','06','12'])
ax[1].legend()
ax[1].set_xlim(0,60)
ax[1].set_ylim(0,60)
ax[1].set_xticks(range(0,61,6))
axe = ax[1].twiny()
axe.set_xticks(range(0,61,6))
axe.set_xticklabels(['12','18','00','06','12','18','00','06','12','18','00'])
# adding a second legend breaks set xticks
line1, = plt.plot(np.nan,np.nan, label='test', linestyle='-',marker='s',color='r')
sec_legend = axe.legend(handles=[line1], loc='upper right')
axe.add_artist(sec_legend)
is this a sequence issue? yes, yes it is. is solving my own discourse by pontificating here acceptable?
modified code to solve:
Just set ticks after call to legend
#this works now
line1, = plt.plot(np.nan,np.nan, label='test', linestyle='-',marker='s',color='r')
sec_legend = axe.legend(handles=[line1], loc='upper right')
axe.add_artist(sec_legend)
axe = ax[1].twiny()
axe.set_xticks(range(0,61,6))
axe.set_xticklabels(['12','18','00','06','12','18','00','06','12','18','00'])
In case any one else has a Problem Exists Between Keyboard and Chair moment.
happy matplotlibbing
jimmyc
[edited by @tacaswell to add code markup]