x=[5 6 7 8 9 ];
y1=[5.39 5.12 4.91 4.73 4.68 ];
y2=[5.03 4.85 4.59 4.49 4.47 ];
plot(x, y1, 'r-o',x, y2, 'b-s')
legend('A', 'B');
hold on
[a1,h1,h2]=plotyy(x, y1,x, y2);
set(h1,'LineStyle','-o','Color','r');%设置右侧线型
set(h2,'LineStyle','-s','Color','b');%设置左侧线型
hold off
xlim auto
python 方法1:(两个坐标颜色一样,一致的后面再说)
fig = plt.figure()
ax = fig.add_subplot(111)
rms = ax.plot( Swdown, 'g-*', label = 'RMS')
#lns2 = ax.plot(time, Rn, 'b--', label = 'Rn')
ax2 = ax.twinx()
std = ax2.plot( temp, 'r-.', label = 'STD')
# added these three lines
lns = rms+std
labs = [l.get_label() for l in lns]
ax.legend(lns, labs, loc=0)
ax.grid()
ax.set_xlabel("PRN")
ax.set_ylabel(r"RMS /ns")
ax2.set_ylabel(r"STD /ns")
ax2.set_ylim(0, 35)
ax.set_ylim(-20,100)
ax.set_title("RMS and STD of Forecast statistics")
ax2.yaxis.label.set_color("r")
ax2.tick_params(colors="r")
加两句,变换一下轴的颜色。