使用 Python 的动画字体大小

Font size in animation using Python

如何增加热图中数字的字体大小以及颜色条?数字太小,如下所示。

import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from celluloid import Camera

a = np.array([[0.31131114, 0.96641729, 0.72632796],
       [0.42412489, 0.66088661, 0.60893906],
       [0.64454019, 0.509509  , 0.66285615]])

b = np.array([0.31131114, 0.42412489, 0.509509  , 0.64454019])

fig, (ax1, cbar_ax) = plt.subplots(ncols=2, gridspec_kw={'width_ratios': [20, 2]},
                                   figsize=(25,25))
camera = Camera(fig)
sns.set_style('white')
rectangles = []
for bb in b.flatten():
    sns.heatmap(a, linewidth=2, ax=ax1, annot=True, cbar_ax=cbar_ax)
    rectangles.append(plt.Rectangle((np.where(a == bb)[1][0], np.where(a == bb)[0][0]), 1,1,
                                    fc='green', ec='green', lw=5, clip_on=False))
    for rect in rectangles:
        ax1.add_patch(rect)
    camera.snap()

animation = camera.animate(interval=800)
animation.save('Today_3x3.gif')
plt.show()

  • 调整你的图形大小,使其更小(所以你的文字,相对来说,更大)

  • 使用 sns.set(font_scale=3) 放大 SNS 字体大小(信用