【问题标题】:Plot outside axis in Matlab在 Matlab 中绘制外轴
【发布时间】:2011-10-21 07:45:03
【问题描述】:

如何用 MATLAB 在轴外绘制一些东西?我想绘制类似于这个数字的东西;

谢谢。

【问题讨论】:

  • 我认为这是不可能的,不幸的是我没有 a.t.m 的许可证。也许您可以通过修改轴属性来做到这一点; mathworks.com/help/techdoc/ref/axes_props.html#Position
  • 我希望通过将酒吧系列的 clipping 设置为 off 来实现这一点,但这似乎对我不起作用。

标签: matlab graphics figure


【解决方案1】:

这是使用两个轴的一种可能技巧:

%# plot data as usual
x = randn(1000,1);
[count bin] = hist(x,50);
figure, bar(bin,count,'hist')
hAx1 = gca;

%# create a second axis as copy of first (without its content), 
%# reduce its size, and set limits accordingly
hAx2 = copyobj(hAx1,gcf);
set(hAx2, 'Position',get(hAx1,'Position').*[1 1 1 0.9], ...
    'XLimMode','manual', 'YLimMode','manual', ...
    'YLim',get(hAx1,'YLim').*[1 0.9])
delete(get(hAx2,'Children'))

%# hide first axis, and adjust Z-order
axis(hAx1,'off')
uistack(hAx1,'top')

%# add title and labels
title(hAx2,'Title')
xlabel(hAx2, 'Frequency'), ylabel(hAx2, 'Mag')

这是之前和之后的情节:

【讨论】:

【解决方案2】:

您可以使用您想要的比例显示一个轴,然后将您的数据绘制在另一个不可见且大到足以容纳您需要的数据的轴上:

f = figure;

% some fake data
x = 0:20;
y = 23-x;
a_max = 20;
b_max = 23;
a_height = .7;

%% axes you'll see
a = axes('Position', [.1 .1 .8 a_height]);
xlim([0 20]);
ylim([0 20]);

%% axes you'll use
scale = b_max/a_max;
a2 = axes('Position', [.1 .1 .8 scale*a_height]);
p = plot(x, y);
xlim([0 20]);
ylim([0 b_max]);
set(a2, 'Color', 'none', 'Visible', 'off');

【讨论】:

    【解决方案3】:

    我遇到了类似的问题,感谢answer,我已经解决了。如果是条形系列,代码如下:

    [a,b] = hist(randn(1000,1)); % generate random data and histogram
    h = bar(b,a); % plot bar series
    ylim([0 70]) % set limits
    set(get(h,'children'),'clipping','off')% turn off clippings
    

    【讨论】:

      猜你喜欢
      • 2017-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-22
      • 1970-01-01
      • 2012-04-16
      • 2016-07-07
      • 2018-01-06
      相关资源
      最近更新 更多