In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this article "how to draw python scatter chart", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to draw python scatter chart" article.
The drawing of one-dimensional and two-dimensional scatter diagram 1. Use pandas.plotting.scatter_matrix function to draw pd.plotting.scatter_matrix (iris_data, figsize= (10,10), alpha=1, hist_kwds= {"bins": 20})
two。 Use seaborn to draw # No. 1 # all variables are put into sns.pairplot (iris_data)
# No.2 # kind: used to control the type of non-diagonal images. Optional 'scatter' and' reg' # diag_kind: used to control the classification of diagonals. Optional 'hist'' and 'kde' sns.pairplot (iris_data, kind='reg', diag_kind='kde') sns.pairplot (iris_data, kind='reg', diag_kind='hist')
After hue classification, pairplot found that no matter from the diagonal distribution map or from the classified scatter map, we can see that for different kinds of flowers, the distribution of sepal length, petal length and petal width is quite different. In other words, these attributes can help us to identify different kinds of flowers. For example, for a flower with shorter sepals and shorter petals and narrower petals, it is likely to be Iris.
# No 3 # hue: classify a field by sns.pairplot (iris_data, hue='species', kind='reg', diag_kind='hist')
# No 4 # vars: study the relationship between two or more variables vars, # xaccounvars: select a specific field in the data and pass it in the form of list. Both x_vars and y_vars should specify sns.pairplot (iris_data, vars= ["sepal length (cm)", "sepal width (cm)"]) sns.pairplot (iris_data, xroomvars = ["petal length (cm)", "sepal width (cm)"], yroomvars = ["petal width (cm)", "sepal length (cm)"])
2. Drawing 3D scatter plot
The 3D scatter plot is drawn by mplot3d module.
# No. 53D from mpl_toolkits.mplot3d import Axes3D dims= {'x':'petal length (cm)', 'y':'petal width (cm)', 'z':'sepal length (cm)'} types=iris_data.species.value_counts (). Index.tolist () print (dims, types) flg=plt.figure () ax=Axes3D (flg) for iris_type in types: tmp_data=iris_ data [iris _ data.species = = iris_type] xMagy Z = tmp_data [dims ['x']], tmp_data [dims ['z']], tmp_data [dims ['z']] ax.scatter (x, y, z, label=iris_type) ax.legend (loc='upper left') ax.set_zlabel (dims ['z']) ax.set_xlabel (dims ['x']) ax.set_ylabel (dims ['y']) plt.show ()
Complete code:
Import pandas as pdfrom sklearn import datasetsimport seaborn as snsimport matplotlib.pyplot as pltdef function (): iris = datasets.load_iris () iris_data = pd.DataFrame (iris.data, columns=iris.feature_names) iris_data ['species'] = iris.target_ namesiris.target] # No. 0 pd.plotting.scatter_matrix (iris_data, figsize= (10, 10), alpha=1 Hist_kwds= {"bins": 20}) # No. 1 # all variables are put in sns.pairplot (iris_data) # No.2 sns.pairplot (iris_data, kind='reg', diag_kind='kde') sns.pairplot (iris_data, kind='reg', diag_kind='hist') # No 3 # hue: classify sns.pairplot (iris_data, hue='species', kind='reg') for a field Diag_kind='hist') # No 4 # vars: study the relationship between two or more variables, vars, # xroomvarsdjysimplvars: select specific fields in the data It is important to note that the input is in the form of list Both x_vars and y_vars should specify sns.pairplot (iris_data, vars= ["sepal length (cm)", "sepal width (cm)"]) sns.pairplot (iris_data, xroomvars = ["petal length (cm)", "sepal width (cm)"], yroomvars = ["petal width (cm)", "sepal length (cm)"]) # No. 53 d from mpl_toolkits.mplot3d import Axes3D dims= {'x':'petal length (cm)' 'y':'petal width (cm)', 'z':'sepal length (cm)'} types=iris_data.species.value_counts (). Index.tolist () print (dims, types) flg=plt.figure () ax=Axes3D (flg) for iris_type in types: tmp_data=iris_ data [iris _ data.species = = iris_type] x tmp_data [dims ['x']], tmp_data [dims ['z']] Tmp_data [dims ['z']] ax.scatter (x, y, z Label=iris_type) ax.legend (loc='upper left') ax.set_zlabel (dims ['z']) ax.set_xlabel (dims ['x']) ax.set_ylabel (dims ['y']) print (iris_data) plt.show () if _ _ name__ = ='_ main__': function () these are the contents of this article on "how to draw a python scatter chart" I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.