Matlab 中子图中的放大/缩小图
我在尝试按照我想要的方式绘制一些数据时遇到了一些麻烦 - 任何建议将不胜感激。
left
和 right
是从其他地方获得的几十万长度的向量。 下面的代码绘制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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
考虑以下示例:
如果您希望较小轴的背景颜色不透明,只需将它们的颜色设置为白色:
Consider the following example:
If you want the background color of the smaller axes to be opaque, just set their colors to white:
要更改背景,请使用(对于红色背景)
关于子图,如果您发布不起作用的代码,它将有所帮助。
To change the background, use (for red background)
Regarding the subplot, if you post the code that doesn't work it will help.