matplotlib学习笔记(3)---热力图(Heat Map)

matplotlib学习笔记(3)---热力图(Heat Map),第1张

matplotlib学习笔记(3)---热力图(Heat Map) matplotlib学习笔记(3)—热力图(Heat Map)
import matplotlib.pylab as plt
import seaborn as sns
import numpy as np
import pandas as pd
io= r'D:/shuju.xlsx'
data = pd.read_excel(io)
data

data数据展示列子

plt.subplots(figsize = (20,10))
sns.set_style('whitegrid')
corrMatt = data[["贮藏年份","棕榈酸",
                  "硬脂酸","油酸",
                  "亚油酸","亚麻酸",
                  "总脂肪酸"]].corr()
# mask = np.array(corrMatt)
mask = np.zeros_like(corrMatt, dtype=np.bool)
mask[np.triu_indices_from(mask)] = True
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
mask[np.tril_indices_from(mask)] = False #下三角
sns.heatmap(corrMatt, mask=mask,
           vmax=.8, square=True,annot=True,cmap = 'Blues_r')
plt.savefig('C:/Users/Desktop/heatmap.png',dpi=100,bbox_inches='tight')


改变热力图的颜色
只需要更改参数中的cmap
使用cmap可以改变图的颜色,cmap可以选择:
Accent, Accent_r, Blues, Blues_r, BrBG, BrBG_r, BuGn, BuGn_r, BuPu, BuPu_r, CMRmap, CMRmap_r, Dark2, Dark2_r, GnBu, GnBu_r, Greens, Greens_r, Greys, Greys_r, OrRd, OrRd_r, Oranges, Oranges_r, PRGn, PRGn_r, Paired, Paired_r, Pastel1, Pastel1_r, Pastel2, Pastel2_r, PiYG, PiYG_r, PuBu, PuBuGn, PuBuGn_r, PuBu_r, PuOr, PuOr_r, PuRd, PuRd_r, Purples, Purples_r, RdBu, RdBu_r, RdGy, RdGy_r, RdPu, RdPu_r, RdYlBu, RdYlBu_r, RdYlGn, RdYlGn_r, Reds, Reds_r, Set1, Set1_r, Set2, Set2_r, Set3, Set3_r, Spectral, Spectral_r, Wistia, Wistia_r, YlGn, YlGnBu, YlGnBu_r, YlGn_r, YlOrBr, YlOrBr_r, YlOrRd, YlOrRd_r, afmhot, afmhot_r, autumn, autumn_r, binary, binary_r, bone, bone_r, brg, brg_r, bwr, bwr_r, cividis, cividis_r, cool, cool_r, coolwarm, coolwarm_r, copper, copper_r, cubehelix, cubehelix_r, flag, flag_r, gist_earth, gist_earth_r, gist_gray, gist_gray_r, gist_heat, gist_heat_r, gist_ncar, gist_ncar_r, gist_rainbow, gist_rainbow_r, gist_stern, gist_stern_r, gist_yarg, gist_yarg_r, gnuplot, gnuplot2, gnuplot2_r, gnuplot_r, gray, gray_r, hot, hot_r, hsv, hsv_r, icefire, icefire_r, inferno, inferno_r, jet, jet_r, magma, magma_r, mako, mako_r, nipy_spectral, nipy_spectral_r, ocean, ocean_r, pink, pink_r, plasma, plasma_r, prism, prism_r, rainbow, rainbow_r, rocket, rocket_r, seismic, seismic_r, spring, spring_r, summer, summer_r, tab10, tab10_r, tab20, tab20_r, tab20b, tab20b_r, tab20c, tab20c_r, terrain, terrain_r, twilight, twilight_r, twilight_shifted, twilight_shifted_r, viridis, viridis_r, vlag, vlag_r, winter, winter_r

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5716240.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存