python制图【1】相关系数热力图
程序员文章站
2024-01-01 11:08:34
会用到的库和方法:pandas 中 corr()、read_csv()matplotlib中figure()seaborn中heatmap()import pandas as pdimport matplotlib.pyplot as pltimport seaborn as sns#导入文件file_path = r'G:\hotel_bookings.csv'df = pd.read_csv(file_path)#复制副本data_copy=df.copy(deep=Tru...
会用到的库和方法:
- pandas 中 corr()、read_csv()
- matplotlib中figure()
- seaborn中heatmap()
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
#导入文件
file_path = r'G:\hotel_bookings.csv'
df = pd.read_csv(file_path)
#复制副本
data_copy=df.copy(deep=True)
#计算相关系数
cor = data_copy.corr()
#设置画面
plt.figure(figsize=(37,37))
#作图,cmap为颜色类型,annot=False不显示数字,vmax最大值,vmin最小值,suqare=true正方形,linewidths划分每个单元格的行的宽度,xticklabels,yticklabels
sns.heatmap(cor,annot=False,vmax=1,square=True,cmap='PuBu',linewidths=.5)
plt.savefig('./cor.jpg')
plt.show()
本文地址:https://blog.csdn.net/IN_Joseph/article/details/107882706