修改饼图标签的字体大小 [英] Modifying font size for pie chart lables

查看:1172
本文介绍了修改饼图标签的字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个简单的饼图脚本,但是无法更改饼图标签的字体大小.有没有简单的方法可以更改它?

I am using a simple script for a pie chart, but I am unable to change the font size of the pie labels. Is there an easy way to change it?

下面是我的绘图代码:

h = pie ([0.1,0.1,0.1,0.1,0.1], {"unlikely","possible","likely","very likely","certain"});
y = 0; 
n = 1; 

colormap([1 1 n;    %// unlikely
          1 1 y;    %// possible
          1 1 y;    %// likely
          1 1 y;    %// very unlikely
          1 1 n;])  %// certainly
ax = gca();
set(ax,'fontsize', 18);
view([270, -90])

推荐答案

要以编程方式设置fontsize或某种类型的图形元素的任何其他属性,应使用 findobj() 功能查找此类型的所有元素.然后,您可以使用单个set命令来设置属性.在您的示例中,您必须编写:

To programmatically set the fontsize or any other property of graphical elements of a certain type you should use the findobj() function to find all elements of this type. Then you can use a single set command to set properties. In your example you have to write:

set(findobj(h,'type','text'),'fontsize',18)

这将更改饼图中所有文本元素的所有字体大小.

This will change all font sizes of all text elements in the pie chart.

我修改了您的示例以显示效果:

I adapted your example to show the effect:

h = pie ([0.1,0.1,0.1,0.1,0.1], {"unlikely","possible","likely","very likely","certain"});
y = 0; 
n = 1; 

colormap([1 1 n;    %// unlikely
          1 1 y;    %// possible
          1 1 y;    %// likely
          1 1 y;    %// very unlikely
          1 1 n;])  %// certainly

view([270, -90])
set(findobj(h,'type','text'),'fontsize',18);

图形输出

这篇关于修改饼图标签的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆