I was trying to make two subplots with twinx axis, 3 curves (curvey,curve1 and curve2) on the first subplot and 3 curves (curvey, curve3 and curve4) on the second subplot. But I'm not getting what I want. I wonder if you guys can help me please.
x = df['curvex']
y = df['curvey']
y1 = df['curve1']
y2 = df['curve2']
y3=df['curve3']
y4=df['curve4']
fig, ax = plt.subplots(figsize=(40,10), dpi=500)
plt.subplot(2,1,1)
fig.subplots_adjust(right=0.75)
twin1 = ax.twinx()
twin2 = ax.twinx()
twin2.spines['right'].set_position(('axes', 1.02))
p1, = ax.plot(x,y, 'bo--', label='curvey', markersize=0.1, linewidth=0.2)
p2, = twin1.plot(x,y1, 'go--', label='curvey1', markersize=0.1, linewidth=0.2)
p3, = twin2.plot(x,y2, 'ro--', label='curvey2', markersize=0.1, linewidth=0.2)
ax.set_xlabel('CURVEX')
ax.set_ylabel('CURVEY')
twin1.set_ylabel('CURVE1')
twin2.set_ylabel('CURVE2')
ax.yaxis.label.set_color(p1.get_color())
twin1.yaxis.label.set_color(p2.get_color())
twin2.yaxis.label.set_color(p3.get_color())
tkw = dict(size=0.5, width=0.2)
ax.tick_params(axis='y', colors=p1.get_color(), **tkw)
twin1.tick_params(axis='y', colors=p2.get_color(), **tkw)
twin2.tick_params(axis='y', colors=p3.get_color(), **tkw)
ax.legend(handles=[p1,p2,p3])
plt.subplot(2,1,2)
fig.subplots_adjust(right=0.75)
twin3 = ax.twinx()
twin4 = ax.twinx()
twin4.spines['right'].set_position(('axes', 1.02))
p1, = ax.plot(x,y, 'bo--', label='curvey', markersize=0.1, linewidth=0.2)
p4, = twin3.plot(x,y3, 'go--', label='curvey4', markersize=0.1, linewidth=0.2)
p5, = twin4.plot(x,y4, 'ro--', label='curvey5', markersize=0.1, linewidth=0.2)
ax.set_xlabel('CURVEX')
ax.set_ylabel('CURVEY')
twin3.set_ylabel('CURVE4')
twin4.set_ylabel('CURVE5')
ax.yaxis.label.set_color(p1.get_color())
twin3.yaxis.label.set_color(p4.get_color())
twin4.yaxis.label.set_color(p5.get_color())
tkw = dict(size=0.5, width=0.2)
ax.tick_params(axis='y', colors=p1.get_color(), **tkw)
twin3.tick_params(axis='y', colors=p4.get_color(), **tkw)
twin4.tick_params(axis='y', colors=p5.get_color(), **tkw)
ax.legend(handles=[p1,p4,p5])
plt.show()
This is what I was getting. Y-axes on the left should be separated, for each subplot. Curvey, curve1 and curve2 should be on the first subplot, and curvey, curve3 and curve4 should be on the second subplot.In total, I want to see 3 curves in each subplot. I can't see legend neither. Y scales on the left and right are wrong also since the code is not good, I guess