How to draw data Graph with Python Pandas tool
This article mainly shows you the "Python Pandas tool data map how to achieve", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "Python Pandas tool data map how to achieve" this article.
Background introduction
DataFrame and Series of Pandas encapsulate a simple drawing function on the basis of Matplotlib, which makes it easy to visually view the results in the process of data processing.
Line chart import pandas as pdimport numpy as npimport matplotlib.pyplot as pltdata=np.random.randn (5 data 2) * 10df=pd.DataFrame (np.abs (data), index= [1 pint 2, 3 recital 4 5], columns= [1 recorder 2]) df.plot () plt.show ()
Bar graph import pandas as pdimport numpy as npimport matplotlib.pyplot as pltdata=np.random.randn (5 data 2) * 10df=pd.DataFrame (np.abs (data), index= [1 recorder 2, 3 dagger 4 5], columns= [1 recorder 2]) df.plot (kind='bar') plt.show ()
Horizontal bar graph import pandas as pdimport numpy as npimport matplotlib.pyplot as pltdata=np.random.randn (5 data 2) * 10df=pd.DataFrame (np.abs (data), index= [1 meme 2, 3 dagger 4 5], columns= [1 mine2]) df.plot (kind='barh') plt.show ()
Stacking graph import pandas as pdimport numpy as npimport matplotlib.pyplot as pltdata=np.random.randn (5 data 2) * 10df=pd.DataFrame (np.abs (data), index= [1 recorder 2, 3 dagger 4 5], columns= [1 recorder 2]) df.plot (kind='bar',stacked=True) plt.show ()
Import pandas as pdimport numpy as npimport matplotlib.pyplot as pltdata=np.random.randn (5Magne2) * 10df=pd.DataFrame (np.abs (data), index= [1pc2, 3d4], columns= [1d2]) df.plot (kind='barh',stacked=True) plt.show ()
Scatter plot
Data is usually a collection of points
It is often used to draw all kinds of correlation, and it is suitable to study the relationship between different variables.
XRX coordinate position
YRV y coordinate position
S: the size of the scatter
C: scatter color
Import pandas as pdimport numpy as npimport matplotlib.pyplot as pltdata=np.random.randn (5meme 2) * 10df=pd.DataFrame (np.abs (data), index= [1pje 2je 3je 4je 5], columns= ['Awaye Ling B']) df.plot (kind='scatter',x='A',y='B',s=df.A*100,c='red') plt.show ()
Pie chart import pandas as pdimport numpy as npimport matplotlib.pyplot as pltdf=pd.Series (3*np.random.rand (4), index= ['axiajiaoyuzhuo']) df.plot.pie (figsize= (6)) plt.show ()
Honeycomb diagram
Reflect the number of times the data appear
Import pandas as pdimport numpy as npimport matplotlib.pyplot as pltdf=pd.DataFrame (np.random.randn (1000) 2), columns= ['axiajiaoyuanb']) df.plot.hexbin (Xuezhuaqiangpaiyaoyangbaojia) plt.show ()
Box diagram
Based on the five numerical characteristics of minimum, upper quartile, median, lower quartile and maximum, the standard way of data distribution can be seen whether the data is symmetrical or not, which is suitable for showing the distribution of a group of data.
Import pandas as pdimport numpy as npimport matplotlib.pyplot as pltdf=pd.DataFrame (np.random.randn (1000) 2), columns= ['axiajiaozhongb']) df.plot (yauddf.columnsddf.columnsrect kindling box) plt.show ()
Draw a subgraph
Subplots: the default False is True if subgraphs are drawn for each column.
Layout: subgraph layout
Figsize: canvas siz
Import pandas as pdimport numpy as npimport matplotlib.pyplot as pltdf=pd.DataFrame (np.random.randn (5jue 2), columns= ['axiaojiaoyuanb']) df.plot (subplots=True,layout= (2pyr3), figsize= (10pime 10), kind='bar') plt.show ()
These are all the contents of the article "how to draw data graphs with Python Pandas tools". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!