如何编辑标签字体大小在Python中建立一个树形图与squarify?

问题描述 投票:4回答:2

我使用的是squarify包在python,codeLink,绘制treemapwikiTreemapArticle。在此基础上example,我可以产生一个树形图,但我无法看到如何在广场标签的fontsizes可以修改。在脚本的基本路线是:

ax = squarify.plot(countryPop, color=colors, label=labels, ax=ax, alpha=.7)

在这里,我不能添加“字号”属性。我将如何改变标签的尺寸?

python matplotlib plot treemap
2个回答
5
投票

squarify工作在matplotlib pyplot那么你只需要改变pyplot的德字号。

我用做我的绘图代码以后的事。

SMALL_SIZE = 13
MEDIUM_SIZE = 18
BIGGER_SIZE = 23

plt.rc('font', size=MEDIUM_SIZE)          # controls default text sizes
plt.rc('axes', titlesize=BIGGER_SIZE)     # fontsize of the axes title
plt.rc('axes', labelsize=BIGGER_SIZE)     # fontsize of the x and y labels
plt.rc('xtick', labelsize=MEDIUM_SIZE)    # fontsize of the tick labels
plt.rc('ytick', labelsize=MEDIUM_SIZE)    # fontsize of the tick labels
plt.rc('legend', fontsize=SMALL_SIZE)    # legend fontsize
plt.rc('figure', titlesize=BIGGER_SIZE)   # fontsize of the figure title

这样你就可以改变你的情节任何字体,包括squarify treemap情节。


3
投票

更新:现在有改变通过text_kwargs参数的字体大小(squarify == 0.3.0或更高版本)的可能性:

ax = squarify.plot(countryPop, color=colors, label=labels, ax=ax, bar_kwargs={'alpha':.7}, text_kwargs={'fontsize':10})
© www.soinside.com 2019 - 2024. All rights reserved.