如何将MATLAB图的插图与框的右上边缘对齐,如图所示?
该示例是使用GNU R生成的,如How to add an inset (subplot) to "topright" of an R plot?
中所述答案 0 :(得分: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)
输出:
你可以想象一下你可以使用新的轴位置,以便外边框与大边框重合,但这应该让你去:)