在 Matlab 中绘制外轴

发布于 2024-11-28 14:06:16 字数 120 浏览 0 评论 0原文

如何使用 MATLAB 绘制轴外的内容?我想绘制与此图类似的东西;

在轴外绘制条形图

谢谢。

How to plot something outside the axis with MATLAB? I had like to plot something similar to this figure;

Plot with bar outside axis

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

醉城メ夜风 2024-12-05 14:06:16

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

%# 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')

这是之前和之后的图:

before_screenshot
after_screenshot

Here is one possible trick by using two axes:

%# 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')

and here is the plot before and after:

before_screenshot
after_screenshot

可是我不能没有你 2024-12-05 14:06:16

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

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');

You can display one axis with the scale you want, then plot your data on another axis which is invisible and large enough to hold the data you need:

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');
瑶笙 2024-12-05 14:06:16

我遇到了类似的问题,并且由于这个 回答。对于条形系列,代码如下:

[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

result

I had similar problem and I've solved it thanks to this answer. In case of bar series the code is as follows:

[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

result

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文