找回密码
 注册
Simdroid-非首页
查看: 58|回复: 3

pie函数求助

[复制链接]
发表于 2011-3-15 22:21:41 | 显示全部楼层 |阅读模式 来自 湖北武汉
我用h=pie(x,y,str)的函数形式画了饼图,str是字符串向量,如str=['石英充填:' '23%']的形式;,现在要改变str字符显示的文字大小,我用set(h,'FontSize',8)提示错误,请问是什么问题,怎么解决?
发表于 2011-3-16 09:31:25 | 显示全部楼层 来自 河北廊坊
Simdroid开发平台
1# iryouott
给你一个例子:

  1. clear;clc;close all
  2. h = pie(1:3,{'Taxes','Expenses','Profit'});
  3. arrayfun(@(x)set(h(x),'FontSize',x*10),2:2:6);
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×

评分

1

查看全部评分

回复 不支持

使用道具 举报

发表于 2011-3-16 09:40:36 | 显示全部楼层 来自 天津
在图形界面用鼠标修改吧,也许还方便点.或者在
function hh = pie(varargin)
%PIE    Pie chart.
%   PIE(X) draws a pie plot of the data in the vector X.  The values in X
%   are normalized via X/SUM(X) to determine the area of each slice of pie.
%   If SUM(X) <= 1.0, the values in X directly specify the area of the pie
%   slices.  Only a partial pie will be drawn if SUM(X) < 1.
%
%   PIE(X,EXPLODE) is used to specify slices that should be pulled out from
%   the pie.  The vector EXPLODE must be the same size as X. The slices
%   where EXPLODE is non-zero will be pulled out.
%
%   PIE(...,LABELS) is used to label each pie slice with cell array LABELS.
%   LABELS must be the same size as X and can only contain strings.
%
%   PIE(AX,...) plots into AX instead of GCA.
%
%   H = PIE(...) returns a vector containing patch and text handles.
%
%   Example
%      pie([2 4 3 5],{'North','South','East','West'})
%
%   See also PIE3.

%   Clay M. Thompson 3-3-94
%   Copyright 1984-2004 The MathWorks, Inc.
%   $Revision: 1.16.4.6 $  $Date: 2004/04/10 23:31:59 $

% Parse possible Axes input
[cax,args,nargs] = axescheck(varargin{:});

if nargs==0, error('Not enough input arguments.'); end

x = args{1}(:); % Make sure it is a vector
args = args(2:end);

if nargs>3, error('Too many input arguments.'); end

nonpositive = (x <= 0);
if any(nonpositive)
  warning('MATLAB:pie:NonPositiveData',...
          'Ignoring non-positive data in pie chart.');
  x(nonpositive) = [];
end
xsum = sum(x);
if xsum > 1+sqrt(eps), x = x/xsum; end

% Look for labels
if nargs>1 & iscell(args{end})
  txtlabels = args{end};
  if any(nonpositive)
    txtlabels(nonpositive) = [];
  end
  args(end) = [];
else
  for i=1:length(x)
    if x(i)<.01,
      txtlabels{i} = '< 1%';
    else
      txtlabels{i} = sprintf('%d%%',round(x(i)*100));
    end
  end
end

% Look for explode
if isempty(args),
   explode = zeros(size(x));
else
   explode = args{1};
   if any(nonpositive)
     explode(nonpositive) = [];
   end
end

explode = explode(:); % Make sure it is a vector

if length(txtlabels)~=0 & length(x)~=length(txtlabels),
  error('Cell array of strings must be the same length as X.');
end

if length(x) ~= length(explode),
  error('X and EXPLODE must be the same length.');
end

cax = newplot(cax);
next = lower(get(cax,'NextPlot'));
hold_state = ishold(cax);

theta0 = pi/2;
maxpts = 100;
inside = 0;

h = [];
for i=1:length(x)
  n = max(1,ceil(maxpts*x(i)));
  r = [0;ones(n+1,1);0];
  theta = theta0 + [0;x(i)*(0:n)'/n;0]*2*pi;
  if inside,
    [xtext,ytext] = pol2cart(theta0 + x(i)*pi,.5);
  else
    [xtext,ytext] = pol2cart(theta0 + x(i)*pi,1.2);
  end
  [xx,yy] = pol2cart(theta,r);
  if explode(i),
    [xexplode,yexplode] = pol2cart(theta0 + x(i)*pi,.1);
    xtext = xtext + xexplode;
    ytext = ytext + yexplode;
    xx = xx + xexplode;
    yy = yy + yexplode;
  end
  theta0 = max(theta);
  h = [h,patch('XData',xx,'YData',yy,'CData',i*ones(size(xx)), ...
               'FaceColor','Flat','parent',cax), ...
         text(xtext,ytext,txtlabels{i},...
              'HorizontalAlignment','center','parent',cax)];
end

if ~hold_state,
  view(cax,2); set(cax,'NextPlot',next);
  axis(cax,'equal','off',[-1.2 1.2 -1.2 1.2])
end

if nargout>0, hh = h; end

% Register handles with m-code generator
if ~isempty(h)
  mcoderegister('Handles',h,'Target',h(1),'Name','pie');
end

这个matlab的pie函数中的
  h = [h,patch('XData',xx,'YData',yy,'CData',i*ones(size(xx)), ...
               'FaceColor','Flat','parent',cax), ...
         text(xtext,ytext,txtlabels{i},...
              'HorizontalAlignment','center','parent',cax)];
的text段改写成
text(xtext,ytext,txtlabels{i},...
              'HorizontalAlignment','center','parent',cax),'FontSize',15;
15为数字大小,具体按你自己的要求改动.颜色也可以类似舔加.

评分

1

查看全部评分

回复 不支持

使用道具 举报

 楼主| 发表于 2011-3-16 09:46:07 | 显示全部楼层 来自 湖北武汉
好的,谢谢两位的指点
回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Simapps系列直播

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-10-4 23:32 , Processed in 0.030244 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表