Subplot existing plots with left, right, bottom, and top axes.
2 次查看(过去 30 天)
显示 更早的评论
Hello
I have to plot with different units like the left axis has km unit and the right axis has mile unit. When I plot the right and top axes not shown in the subplot. Please see the code.
figure('Renderer', 'painters', 'Position', [10 10 700 500])
h1=figure (1)
x=0:1:10;
y=x.^2;
ax1 = gca;
plot(x,y)
grid on
set(gca,'GridLineStyle',':')
xt = get(ax1,'XTick')
yt = get(ax1,'YTick')
ax2 = copyobj(ax1,h1);
set(ax2,'XAxisLocation','top')
set(ax2,'YAxisLocation','right')
x = xt*3.28084;
y = yt*10.7639;
set(ax2,'XTickLabel',x)
set(ax2,'YTickLabel',y)
figure('Renderer', 'painters', 'Position', [10 10 700 500])
h2=figure (2)
x=0:1:10;
y=x.^0.5;
ax1 = gca;
plot(x,y)
grid on
set(gca,'GridLineStyle',':')
xt = get(ax1,'XTick')
yt = get(ax1,'YTick')
ax2 = copyobj(ax1,h2);
set(ax2,'XAxisLocation','top')
set(ax2,'YAxisLocation','right')
x = xt*3.28084;
y = yt*10.7639;
set(ax2,'XTickLabel',x)
set(ax2,'YTickLabel',y)
figlist=get(groot,'Children');
newfig=figure;
tcl=tiledlayout(newfig,'flow')
for i = 1:numel(figlist)
figure(figlist(i));
ax=gca;
ax.Parent=tcl;
ax.Layout.Tile=i;
end
0 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!