首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何编辑在Python中使用squarify构建树地图时的标签字体大小?

如何编辑在Python中使用squarify构建树地图时的标签字体大小?
EN

Stack Overflow用户
提问于 2016-10-23 21:04:22
回答 3查看 7.6K关注 0票数 9

我在python,codeLink中使用一个codeLink包来绘制treemapwikiTreemapArticle。基于这个示例,我可以生成一个树状地图,但是我无法看到如何修改方框中标签的字体大小。脚本中的基本行是:

代码语言:javascript
复制
ax = squarify.plot(countryPop, color=colors, label=labels, ax=ax, alpha=.7)

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

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2018-12-03 09:08:16

更新:现在可以通过text_kwargs参数更改squarify==0.3.0大小(squarify==0.3.0或更高版本):

代码语言:javascript
复制
ax = squarify.plot(countryPop, color=colors, label=labels, ax=ax, bar_kwargs={'alpha':.7}, text_kwargs={'fontsize':10})
票数 14
EN

Stack Overflow用户

发布于 2017-08-09 20:43:28

squarifymatplotlib pyplot上工作,因此只需更改pyplot的字体大小即可。

我经常在我的密谋代码上做下面的事情。

代码语言:javascript
复制
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绘图中的字体。

票数 6
EN

Stack Overflow用户

发布于 2019-11-19 14:57:20

代码语言:javascript
复制
#Fonts demo (kwargs)
#Set font properties using kwargs.

#See Fonts demo (object-oriented style) to achieve the same effect using setters.


squarify.plot(sizes=volume, label=labels,text_kwargs={'fontsize':10, 'fontname':"Times New Roman Bold",'weight':'bold'},color=color_list, alpha=0.9)


#Fonts demo(kwargs) 
# https://matplotlib.org/3.1.0/gallery/text_labels_and_annotations/fonts_demo_kw.html
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40207784

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档