import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
plt.rcParams['font.size']=15
np.random.seed(1)
plt.figure(figsize=(12,3.5))
ax0 = plt.subplot(121)
ax1 = ax0.twinx()
ax2 = plt.subplot(122)
ax3 = ax2.twinx()
ax1.get_shared_y_axes().join(ax1, ax3)
ax0.plot(np.random.rand(1) * np.random.rand(10),'r')
ax0.grid()
ax1.plot(10*np.random.rand(1) * np.random.rand(10),'b')
ln2 = ax2.plot(3*np.random.rand(1) * np.random.rand(10),'r',label='red')
ax2.grid()
ln3 = ax3.plot(10*np.random.rand(1) * np.random.rand(10),'b',label='blue')
# legend
lns = ln2 + ln3
labs = [l.get_label() for l in lns]
ax3.legend(lns, labs, bbox_to_anchor=(1.1, 1), loc='upper left', borderaxespad=0, )
plt.show()
Recommended Posts