使用axis類來定義:python
from matplotlib.figure import Figure from matplotlib.text import Text featp = df.plot(kind='barh', x='feature', y='fscore', legend=False, figsize=(6, 6)) fig_featp = featp.get_figure() assert isinstance(fig_featp, Figure) axs = fig_featp.get_axes() for ax in axs: for tick in ax.get_yticklabels(): tick.set(fontname=font_name, fontsize=12) for tick in ax.get_xticklabels(): print(type(tick)) assert isinstance(tick, Text) tick.set(fontname=font_name, fontsize=12) # tick.set_fontsize(12) tick.set_fontname(font_name) plt.rcParams.update({'figure.autolayout': True}) plt.show() plt.close()