Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to draw a Chart in Pandas

Shulou Source: shulou.com Published: 2022-06-01 19:02:40 10月05日 Update

This article mainly introduces how to draw a chart in Pandas, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Import pandas as pdimport numpy as np# line chart s=pd.Series (np.random.randn (10), index=np.arange (0jing100jing10) s.plot ()

Df=pd.DataFrame (np.random.randn (10jue 4), index=np.arange (0Jing 100jue 10) Columns=list ('ABCD') print (df) df.plot () ABC D0-0.358499 1.242513-1.200230 0.21805110-1.540113-0.344976-1.509415 1.16226020 0.680961 0.398406-0.429856 1.02773230 0.545883-0.101128 1.747935 0.42318740 0.763575-0.682698 0.885915 0.79683550-2.419253-0.794231-1.100932-0 . 30959160 1.212027 0.684612-0.035615 0.99992770 0.362055-1.851297 0.860120 1.27199680-1.199978-1.158961 0.644087-0.84050390 2.033464 0.301777-0.629141-0.702707

Import matplotlib.pyplot as plts=pd.Series (np.random.randn (16), index=list ('abcdefghijklmnop')) fig,aexs=plt.subplots (2) # Vertical histogram s.plot (ax=aexs [0], kind='bar') # horizontal histogram s.plot (ax=aexs [1], kind='barh')

# stacked bar chart df=pd.DataFrame (np.random.randn (10jing4), index=np.arange (0pence100d10), columns=list ('ABCD') df.plot (kind='bar',stacked=True) plt.show ()

# hist histogram df=pd.DataFrame ({'A':np.random.randn (1000),' B':np.random.randn (1000)}) df.plot (kind='hist',bins=500) plt.show ()

Df2=pd.DataFrame ({'C':np.random.randn (1000)}) df3=pd.concat ([df,df2], axis=1) print (df3) A B C0-0.857916 1.603299-0.5848071-0.192799-0.824972 1.1386442-1.780869-0.501384 1.3181043 0.916919-0.564578 0.8328444-0.153033-0.381179-0.122554. .. 995 0.188451-0.763563 0.230478996 0.371608-0.946306 0.318904997 0.299794-0.420749 0.276406998-0.193156-0.091357-0.926047999 0.871653 1.204641-1.030529 [1000 rows x 3 columns] # scatter figure data=df3 [['Awesome rows'] data.plot.scatter.

Pd.plotting.scatter_matrix (data,color='g',alpha=0.3) array ([,], [,], [,]], dtype=object)

Thank you for reading this article carefully. I hope the article "how to draw a Chart in Pandas" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Articles columns charts values interests at the same time more friends levels histograms knowledge lines editing industry information information channels channels references learning help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Microsoft Shulou Information NVidia Xiaomi