1

如何将 MATLAB 绘图的插图与框的右上角对齐,如图所示?

Gnu R 中的示例

该示例是使用 GNU R 生成的,如如何将插图(子图)添加到 R 图的“右上角”中所述?

4

1 回答 1

2

这是一种方法:

基本上创建一个带有轴的图形,然后添加一个新轴,将其放置到特定位置并为其提供所需的大小。

代码:

clc
clear
close all

%// Dummy data
x = -20:0;
x2 = x(5:10);
%// Zoomed region to put into inset.

y = x.^2;
y2 = y(5:10);

%// Create a figure
hFig = figure(1);

%// Plot the original data
hP1 = plot(x,y);

xlabel('Original x','FontSize',18)
ylabel('Original y','FontSize',18)

hold on

%// Add an axes and set its position to where you want. Its in normalized
%// units

hAxes2 = axes('Parent',hFig,'Position',[.58 .6 .3 .3]);

%// Plot the zommed region
plot(x2,y2,'Parent',hAxes2)

%// Set the axis limits and labels

set(gca,'Xlim',[x(5) x(10)])
xlabel('Zoomed x','FontSize',16)
ylabel('Zommed y','FontSize',16)

并输出:

在此处输入图像描述

想象一下,您可以使用新的轴位置,以使外边界与大边界重合,但这应该可以帮助您:)

于 2015-02-23T22:05:04.217 回答