简体   繁体   中英

pandas DataFrame.plot() method

I'm new to data science and trying some python libraries. I know it sound a bit silly but I'm confused with the code below, which i found on the pandas docs. I'm assuming that 'ts' is a pd obj, but how exactly a pd object can use matplotlib method here? What's the connection between pandas and matplotlib? Can someone explain that to me, thank you.

In [3]: ts = pd.Series(np.random.randn(1000),index=pd.date_range('1/1/2000', periods=1000))


In [4]: ts = ts.cumsum()

In [5]: ts.plot()

Out[5]: <matplotlib.axes._subplots.AxesSubplot at 0x7fa17967caf0>`

Matplotlib is a library that makes it easy to generate plots in Python. Pandas is a library that helps you perform vector and matrix operations in Python.

According to the Pandas docs :

The plot method on Series and DataFrame is just a simple wrapper around plt.plot()

So the only connection between Pandas and Matplotlib is that Pandas uses Matplotlib to generate the plot for you.

If you want to see that plot, you have to add a couple of extra lines:

import matplotlib.pyplot as plt
plt.show()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM