【问题标题】:Zoomed In/Out Plots within Subplots in MatlabMatlab中子图中的放大/缩小图
【发布时间】:2011-07-11 04:35:30
【问题描述】:

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

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 做同样的事情,然后将每对图显示为一个子图,两个子图并排显示。我已经尝试调整上面的操作方式以使用子图,但显然我做错了,因为我一直在处理每个子图的内容并最终得到两个空子图。

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

【问题讨论】:

  • 如果您使用subplot,它会为您设置不同的轴位置。因此,如果您稍后更改轴位置(使用 set 命令),您可能会弄乱子图。如果您发布的代码不符合您的要求,这可能会有所帮助。
  • @Itamar Katz:+1 评论帮助我意识到出了什么问题。

标签: matlab plot


【解决方案1】:

考虑以下示例:

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

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

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

【讨论】:

  • 谢谢 - 这正是我想要的。另外,我打算在 Itamar Katz 发表评论后手动制作并排图,但我从来没有想过制作子图,记录它们的位置,然后删除它们。
【解决方案2】:

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

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

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

【讨论】:

    猜你喜欢
    • 2016-06-01
    • 2013-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-22
    • 2013-12-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多