Matlab 中子图中的放大/缩小图

发布于 2024-11-19 06:44:24 字数 696 浏览 2 评论 0原文

我在尝试按照我想要的方式绘制一些数据时遇到了一些麻烦 - 任何建议将不胜感激。

leftright 是从其他地方获得的几十万长度的向量。 下面的代码绘制left两次 - 第二个图位于第一个图的顶部,大致朝向一个角。

ax1 = axes;
plot(ax1, left, 'b');
set(ax1, 'xlim', [7.075*10^4 7.5*10^4]);
set(ax1, 'ylim', [-0.02 0.02]);

ax2 = axes('Position', get(ax1,'Position'), 'XAxisLocation', 'top', 'YAxisLocation', 'right', 'Color', 'none', 'XColor', 'k', 'YColor', 'k', 'NextPlot', 'add');
plot(ax2, left, 'b');
set(ax2, 'Units', 'normalized', 'Position', [0.6 0.60 0.25 0.25]);

我想做的是对 right 进行同样的操作,然后将每对图显示为子图,两个子图并排。我已经尝试调整上面的方式来使用子图,但我显然做错了一些事情,因为我继续破坏每个子图的内容并最终得到两个空子图。

另外,是否可以防止较小的插图具有透明背景?

I've run into a bit of a hiccup trying to plot some data in the way I want it - any advice would be greatly appreciated.

left and right are vectors of a few hundred thousand in length, obtained elsewhere.
The code below plots left, twice - the second plot lies on top of the first, roughly towards one corner.

ax1 = axes;
plot(ax1, left, 'b');
set(ax1, 'xlim', [7.075*10^4 7.5*10^4]);
set(ax1, 'ylim', [-0.02 0.02]);

ax2 = axes('Position', get(ax1,'Position'), 'XAxisLocation', 'top', 'YAxisLocation', 'right', 'Color', 'none', 'XColor', 'k', 'YColor', 'k', 'NextPlot', 'add');
plot(ax2, left, 'b');
set(ax2, 'Units', 'normalized', 'Position', [0.6 0.60 0.25 0.25]);

What I'd like to do is have the same kind of thing for right, and then display each pair of plots as a subplot, with the two subplots side by side. I've tried adapting the way I'm doing it above to use subplot, but I'm obviously doing something wrong since I keep on nuking the contents of each subplot and ending up with two empty subplots.

Also, is it possible to prevent the smaller inset plot from having a transparent background?

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

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

发布评论

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

评论(2

秋心╮凉 2024-11-26 06:44:24

考虑以下示例:

%# sample data
x = 1:100;
left = randn(100,1);
right = cumsum(rand(100,1)-0.5);

%# build axes positions
hBig = [subplot(121) subplot(122)];         %# create subplots
posBig = get(hBig, 'Position');             %# record their positions
delete(hBig)                                %# delete them
posSmall{1} = [0.275 0.63 0.16 0.24];
posSmall{2} = [0.717 0.63 0.16 0.24];

%# create axes (big/small)
hAxB(1) = axes('Position',posBig{1});
hAxB(2) = axes('Position',posBig{2});
hAxS(1) = axes('Position',posSmall{1});
hAxS(2) = axes('Position',posSmall{2});

%# plot
plot(hAxB(1), x, left, 'b');
plot(hAxB(2), x, right, 'b');
plot(hAxS(1), x, left, 'r');
plot(hAxS(2), x, right, 'r');

%# set axes properties
set(hAxB, 'XLim',[1 100], 'YLim',[-10 10]);
set(hAxS , 'Color','none', 'XAxisLocation','top', 'YAxisLocation','right');

screenshot

如果您希望较小轴的背景颜色不透明,只需将它们的颜色设置为白色:

set(hAxS , 'Color','w')

Consider the following example:

%# sample data
x = 1:100;
left = randn(100,1);
right = cumsum(rand(100,1)-0.5);

%# build axes positions
hBig = [subplot(121) subplot(122)];         %# create subplots
posBig = get(hBig, 'Position');             %# record their positions
delete(hBig)                                %# delete them
posSmall{1} = [0.275 0.63 0.16 0.24];
posSmall{2} = [0.717 0.63 0.16 0.24];

%# create axes (big/small)
hAxB(1) = axes('Position',posBig{1});
hAxB(2) = axes('Position',posBig{2});
hAxS(1) = axes('Position',posSmall{1});
hAxS(2) = axes('Position',posSmall{2});

%# plot
plot(hAxB(1), x, left, 'b');
plot(hAxB(2), x, right, 'b');
plot(hAxS(1), x, left, 'r');
plot(hAxS(2), x, right, 'r');

%# set axes properties
set(hAxB, 'XLim',[1 100], 'YLim',[-10 10]);
set(hAxS , 'Color','none', 'XAxisLocation','top', 'YAxisLocation','right');

screenshot

If you want the background color of the smaller axes to be opaque, just set their colors to white:

set(hAxS , 'Color','w')
つ低調成傷 2024-11-26 06:44:24

要更改背景,请使用(对于红色背景)

set(ax2,'color',[1 0 0])

关于子图,如果您发布不起作用的代码,它将有所帮助。

To change the background, use (for red background)

set(ax2,'color',[1 0 0])

Regarding the subplot, if you post the code that doesn't work it will help.

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