May-16-2022, 05:09 PM
The problem with the code above is .twinx() needs to be an attribute of ax and plot is a method (I think I have the terminology correct) of that.
This works:
If I figure out what's causing the NameError then I'll report back. It's not an issue now, though, since I have figured out this syntax (I can therefore run the whole program).
This works:
fig, axs = plt.subplots(1,2) axs[0].plot(sample_df['Spread_Price'],color='red') axs[0].twinx().plot(sample_df['SPX']) axs[1].twinx().plot(sample_df['Spread_Price']) axs[1].plot(sample_df['SPX'],color='red') plt.tight_layout() plt.show()If I want to switch around primary and secondary axis, then I just need to switch which Series follows .twinx().
If I figure out what's causing the NameError then I'll report back. It's not an issue now, though, since I have figured out this syntax (I can therefore run the whole program).