I have a loop which for a certain condition (occurs e.g 3 times), I\'d like to plot two dataset with twinx, so e.g at the end I have 3 plots on left-y and 3 plots on right-y. Wh
You need to move your "ax2" definition outside the loop (see below). However, this makes seven plots, four on left, three on right. You need to update your "if" condition.
[![import numpy as np
import matplotlib.pyplot as plt
x=np.linspace(0,10,100)
A=5
fig,ax=plt.subplots()
ax2=ax.twinx()
for i in range(0,10):
A=i**2
if(i%3==0):
ax.plot(x,A*np.sin(x),'-ro')
ax2.plot(x,A*x,'-bp')
plt.show()][1]][1]