ax2 = ax1.twinx() # instantiate a second axes that shares the same x-axis
color = 'tab:blue' ax2.set_ylabel('sin', color=color) # we already handled the x-label with ax1 ax2.plot(t, data2, color=color) ax2.tick_params(axis='y', labelcolor=color)
fig.tight_layout() # otherwise the right y-label is slightly clipped plt.show()