Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why the NameError?
#4
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:

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).
Reply


Messages In This Thread
Why the NameError? - by Mark17 - May-16-2022, 02:27 PM
RE: Why the NameError? - by jefsummers - May-16-2022, 04:34 PM
RE: Why the NameError? - by Mark17 - May-16-2022, 04:48 PM
RE: Why the NameError? - by Mark17 - May-16-2022, 05:09 PM
RE: Why the NameError? - by Mark17 - May-17-2022, 08:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  NameError: NameError: global name 'BPLInstruction' is not defined colt 7 4,565 Oct-27-2019, 07:49 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020