0

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.

mpnm
  • 481
  • 1
  • 7
  • 13
  • 2
    https://matplotlib.org/3.1.1/api/index.html#the-pyplot-api – BigBen May 01 '20 at 19:58
  • https://matplotlib.org/3.1.1/tutorials/introductory/pyplot.html#working-with-multiple-figures-and-axes . `pyplot` *uses the current axes. – wwii May 01 '20 at 20:40

0 Answers0