Get the App
SLTechnology News&Howtos  ›  Development  › 

Python carries on the correlation analysis and draws the sample analysis of the scatter

Shulou Source: shulou.com Published: 2022-06-03 11:41:36 10月04日 Update

This article will explain in detail about python correlation analysis and drawing scattered point example analysis, Xiaobian think it is quite practical, so share it for everyone to make a reference, I hope you can gain something after reading this article.

Library needed

The main libraries used are pandas, numpy, matplotlib, seaborn, etc. If you want to use seaborn library, you must introduce matplotlib library, seaborn is its plug-in library.

#1 load pakeage import pandas as pd#read and write tables and table processing import numpy as np#for data computation import geopandas as gpdimport matplotlib.pyplot as pltimport seaborn as snsimport osimport warningswarnings.filterwarnings ("ignore")plt.rc ('font',family='Times New Roman')from glob import globfrom osgeo import gdal,gdal_array, gdalnumericplt.rcParams <$'font.sans-serif']=<$'Simhei'] #Display Chinese plt.rcParams <$'axes.unicode_minus']=False #Display sign data read

Here I am using a portion of my junior brother's data, reading the data here.

df = pd.read_csv('./ JXDY_1.csv',encoding='utf-8')df.head()

Here we do correlation analysis

df.corr()#default is pearson correlation analysis

Then we do a batch scatter plot output, putting correlation data on the graph

a = 2#where the correlation is calculated from the second bit, so I extract for i in df.columns[3:]: a1 = sns.lmplot(y='fruit',x=i,data=df) ax = plt.gca() ax.text(0.9,1,"Pearson:{:.2f}".format(df.corr().iloc[1,a]),transform=ax.transAxes)#Add correlation a = a+1 plt.savefig('./ {}.jpg'.format(i),dpi=300,bbox_inches = 'tight')

The result is done, and then the result output can be!

About "python correlation analysis and drawing scattered point example analysis" This article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.

Tags: Relevance analysis data articles examples more results tables output good practical done content graphics great work brothers articles knowledge minus sign Chinese Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Information Linux Shulou Tech Info Xiaomi