开发者

Zoomed In/Out Plots within Subplots in Matlab

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 to开发者_开发技巧wards 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?


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

Zoomed In/Out Plots within Subplots in Matlab

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

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜