python画热图并输出

import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
import numpy as np

df_2 = np.random.rand(5, 4)  # 自定义数据
# ax = sns.heatmap(uniform_data)
df_2 = pd.DataFrame(df_2)
# df_2.index[2] = "gene"
df_2.columns = ['a', 'b', 'c', 'd']
df_2.index = ['A', 'B', 'C', 'D', 'E']
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
p1 = sns.heatmap(df_2, annot=True,
                 ax=ax, xticklabels="auto",
                 fmt="0.1g",
                 linewidths=.5,
                 annot_kws={"fontsize": 8})
ax.set_title('Heat Map')
ax.set_xlabel('')
ax.set_ylabel('')
s1 = p1.get_figure()
s1.savefig('e:/count/HeatMap.jpg', dpi=1000, bbox_inches='tight')
print(df_2)
print(df_2.index[2])

python画热图并输出_第1张图片

你可能感兴趣的:(python技巧,python,numpy,开发语言)