def add_heat_fig(self,df,fig_explain_str,fig_size): """添加热力图""" df1 = df * 100 df1["设备"] = df1.index + ' ' + df1["date_mean"].apply(lambda x:str('%.2f' % x)) + '%' df1.set_index(['设备'], inplace=True) df1.columns = df1.columns + '\n ' + df1.iloc[-1, :].round(2).map(str) + '%' df_fig = df1.iloc[:-1, :-1] w = 6 dfw = df_fig.shape[0] if dfw>22: w += (dfw-22)*0.16 #在doc中,定一个设备格子宽度为0.25cm=0.16英尺 if w>23.8: w = 23.8 #math.ceil( x ) 向上取整 f, ax = plt.subplots(figsize=(9, w)) sns_plot = sns.heatmap(df_fig, ax=ax, vmin=0, vmax=100, cmap='Greens', annot=False, linewidths=2, cbar=True, cbar_kws={"orientation": "horizontal"},yticklabels=1) # 设置坐标字体方向,通过rotation参数可以调节旋转角度 label_y = ax.get_yticklabels() plt.setp(label_y, rotation=360, horizontalalignment='right') label_x = ax.get_xticklabels() plt.setp(label_x, rotation=60, horizontalalignment='right') sns_plot.tick_params(labelsize='medium') # heatmap 刻度字体大小 10 # colorbar 刻度线设置 cax = plt.gcf().axes[-1] cax.tick_params(labelsize=10) # colorbar 刻度字体大小 # plt.show() self.insert_fig(fig_explain_str,fig_size)
sns.heatmap 热力图的添加,约束格子的高度,设置刻度条字体大小
最新推荐文章于 2025-03-01 10:08:36 发布