Vas*_*ass 5 python plot matplotlib treemap
我使用的是squarify包在python,codeLink,绘制treemap,wikiTreemapArticle。基于此示例,我可以生成树图,但是无法看到如何修改正方形中标签的字体大小。脚本中的基本行是:
ax = squarify.plot(countryPop, color=colors, label=labels, ax=ax, alpha=.7)
Run Code Online (Sandbox Code Playgroud)
从这里我不能添加'fontsize'属性。如何更改标签的尺寸?
Ang*_*ann 10
更新: 现在可以通过text_kwargs参数更改字体大小(squarify==0.3.0 或更高):
ax = squarify.plot(countryPop, color=colors, label=labels, ax=ax, bar_kwargs={'alpha':.7}, text_kwargs={'fontsize':10})
Run Code Online (Sandbox Code Playgroud)
的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
Run Code Online (Sandbox Code Playgroud)
这样,您可以更改图形的任何字体,包括图形中的字体squarify treemap。
| 归档时间: |
|
| 查看次数: |
1979 次 |
| 最近记录: |