Subplot existing plots with left, right, bottom, and top axes.

5 Ansichten (letzte 30 Tage)
Mohammed Ali
Mohammed Ali am 19 Mär. 2021
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

Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by