I am trying to understand why my code will not complete using the ‘.’ operator within the Eclipse IDE, even although the code runs successfully. The code is as follows:
import matplotlib.pyplot as plt
# I can use either of these and get the same result.
# ax = plt.subplot() #(1)
ax = plt.gca() #(2)
ax.plot(people, total_cost, color = 'red') #(3)
ax.set_xlabel('# People') #(4)
ax.set_ylabel('Cost\n(Parking)\t(ticket)') #(5)
What I do not understand is, while the statements (4) and (5) draw a graph accordingly, the attributes of ‘ax’ are not from the ‘pyplot.axes’ class at all, but from the ‘matplotlib.axes’ class. Statement (3) is a call from pyplot.axes
The questions would be then.
- Why can’t I code complete the code using the ‘.’ operator, even though each is a valid statement in (3), (4) and (5) ?
2 While ‘ax’ can be defined as either (1) or (2) from the ‘pyplot.axes’ class, statement (3) is from the ‘matplotlib.axes’ class. How then are both classes being called successfully without one being declared as a result of (1) or (2) ?
- Just as a comment, the arguments for ’matplotlib.axes’ and ‘matplotlib.pyplot.axes’ appear to be the same.
Thanks for any help.
matplotlib.pyplot.plot https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html
matplotlib.pyplot.axes https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.axes.html
matplotlib.axes https://matplotlib.org/stable/api/axes_api.html