Correct me if I'm wrong, but this code creates a figure containing all of the objects and axes with ticks containing the plot elements:
fig = plt.figure()
ax = plt.axes()
Then, this code creates an ndarray
and plots it in the ax
object region:
x = np.linspace(start=0, stop=10)
ax.plot(x, np.sin(x))
But this code produces exactly the same result:
x = np.linspace(start=0, stop=10)
plt.plot(x, np.sin(x))
I see the latter more often, but I wonder why it's preferred more. Do they do the same thing, or are they different, and if so, what are the differences and why is one preferred?
Also, I looked at this post what's the difference between plt.plot(), object.plot(), and it doesn't answer the question, because I'm not asking about a DataFrame
.