[已解决] subplot绘图时问题请教

[复制链接]
ukjames 发表于 2018-10-18 20:42:39
subplot绘图时如何对众多图表设置共同的横坐标以及纵坐标描述啊?

最佳答案


悟得 发表于 2018-10-19 15:09:23
ukjames 发表于 2018-10-19 13:51
指的是xlabel和ylabel

应该是xlabel 里的ax不能是向量。代码在下面。
只能用循环批量设置了,eval 或者sprintf。

  1. function hh = xlabel(varargin)
  2. %XLABEL X-axis label.
  3. %   XLABEL('text') adds text beside the X-axis on the current axis.
  4. %
  5. %   XLABEL('text','Property1',PropertyValue1,'Property2',PropertyValue2,...)
  6. %   sets the values of the specified properties of the xlabel.
  7. %
  8. %   XLABEL(AX,...) adds the xlabel to the specified axes.
  9. %
  10. %   H = XLABEL(...) returns the handle to the text object used as the label.
  11. %
  12. %   See also YLABEL, ZLABEL, TITLE, TEXT.

  13. %   Copyright 1984-2014 The MathWorks, Inc.

  14. narginchk(1,inf);

  15. % if the input has an xlabel property which is a text object, use it to set
  16. % the xlabel on.
  17. [ax,args,nargs] = labelcheck('XLabel',varargin);
  18. if isempty(ax)
  19.     ax = gca;
  20.     args = varargin;
  21. end

  22. if nargs > 1 && (rem(nargs-1,2) ~= 0)
  23.   error(message('MATLAB:xlabel:InvalidNumberOfInputs'))
  24. end

  25. string = args{1};
  26. if isempty(string), string=''; end;
  27. pvpairs = args(2:end);

  28. if isappdata(ax,'MWBYPASS_xlabel')
  29.   h = mwbypass(ax,'MWBYPASS_xlabel',string,pvpairs{:});

  30.   %---Standard behavior
  31. else
  32.     h = get(ax,'XLabel');
  33.     set(h,'FontSizeMode','auto',...
  34.         'FontUnitsMode','auto',...
  35.         'FontWeight',get(ax,'FontWeight'),...
  36.         'FontAngle',get(ax,'FontAngle'),...
  37.         'FontName',get(ax,'FontName'));
  38.     set(h, 'String', string, pvpairs{:});
  39.    
  40. end

  41. if nargout > 0
  42.   hh = h;
  43. end
复制代码

3 条回复


悟得 发表于 2018-10-19 11:33:32
描述指的是啥啊?范围精度这些吗?
  1. x1 = linspace(0,10,100);
  2. y1 = sin(x1);
  3. ax1 = subplot(2,1,1);
  4. plot(ax1,x1,y1)

  5. x2 = linspace(0,5,100);
  6. y2 = sin(x2);
  7. ax2 = subplot(2,1,2);
  8. plot(ax2,x2,y2)

  9. axis([ax1 ax2],[0 10 -1 1])
复制代码

ukjames 发表于 2018-10-19 13:51:43
悟得 发表于 2018-10-19 03:33
描述指的是啥啊?范围精度这些吗?

指的是xlabel和ylabel

悟得 发表于 2018-10-19 15:09:23
ukjames 发表于 2018-10-19 13:51
指的是xlabel和ylabel

应该是xlabel 里的ax不能是向量。代码在下面。
只能用循环批量设置了,eval 或者sprintf。

  1. function hh = xlabel(varargin)
  2. %XLABEL X-axis label.
  3. %   XLABEL('text') adds text beside the X-axis on the current axis.
  4. %
  5. %   XLABEL('text','Property1',PropertyValue1,'Property2',PropertyValue2,...)
  6. %   sets the values of the specified properties of the xlabel.
  7. %
  8. %   XLABEL(AX,...) adds the xlabel to the specified axes.
  9. %
  10. %   H = XLABEL(...) returns the handle to the text object used as the label.
  11. %
  12. %   See also YLABEL, ZLABEL, TITLE, TEXT.

  13. %   Copyright 1984-2014 The MathWorks, Inc.

  14. narginchk(1,inf);

  15. % if the input has an xlabel property which is a text object, use it to set
  16. % the xlabel on.
  17. [ax,args,nargs] = labelcheck('XLabel',varargin);
  18. if isempty(ax)
  19.     ax = gca;
  20.     args = varargin;
  21. end

  22. if nargs > 1 && (rem(nargs-1,2) ~= 0)
  23.   error(message('MATLAB:xlabel:InvalidNumberOfInputs'))
  24. end

  25. string = args{1};
  26. if isempty(string), string=''; end;
  27. pvpairs = args(2:end);

  28. if isappdata(ax,'MWBYPASS_xlabel')
  29.   h = mwbypass(ax,'MWBYPASS_xlabel',string,pvpairs{:});

  30.   %---Standard behavior
  31. else
  32.     h = get(ax,'XLabel');
  33.     set(h,'FontSizeMode','auto',...
  34.         'FontUnitsMode','auto',...
  35.         'FontWeight',get(ax,'FontWeight'),...
  36.         'FontAngle',get(ax,'FontAngle'),...
  37.         'FontName',get(ax,'FontName'));
  38.     set(h, 'String', string, pvpairs{:});
  39.    
  40. end

  41. if nargout > 0
  42.   hh = h;
  43. end
复制代码
回复此楼
您需要登录后才可以回帖 登录 | 注册

本版积分规则

相关帖子
相关文章
热门教程
站长推荐
快速回复 返回顶部 返回列表