Superimposing extra axes in second tile of a tiled chart layout
Ältere Kommentare anzeigen
Running the below appended code gives a figure shown as below. I want the green curve corresponding to y4 (green squares) to appear in the secondary axes (y-right and x-top) of tile 2. I know that I am making a mistake in line 38 (comments are added to this line) of the code by calling the axes corresponding to tile1 instead of tile2. But I do not know how to call the axes for the second tile. Could someone help me with this?
clear; clc;
%% Data for plotting
x1 = (15:15:1800)';
y1 = x1./(1-x1);
y2 = exp(-x1./(1+x1));
y3 = log10(x1);
y4 = log(x1);
x2 = 50*x1;
t = tiledlayout(1,2);
%% Tile 1
ax1 = axes(t);
l1 = plot(ax1,x1,y1,'-bo');
ax1.XAxisLocation = 'bottom';
ax1.YAxisLocation = 'left';
ax1.Color = 'none';
xlabel('time (days)'); ylabel('y1');
axis square;
ax2 = axes(t);
l2 = plot(ax2,x2,y2,'-xr');
ax2.XAxisLocation = 'top';
ax2.YAxisLocation = 'right';
ax2.Color = 'none';
xlabel('Number of cycles'); ylabel('y2');
ax2.XAxis.Exponent = 0; xtickformat('%.0f');
axis square;
legend([l1;l2],'y1','y2','Location','East');
ax1.Box = 'off';
ax2.Box = 'off';
%% Tile 2
ax3 = nexttile;
l3 = plot(ax3,x1,y3,'-pm');
ax3.Color = 'none';
xlabel('time (days)'); ylabel('y3');
axis square
ax4 = axes(t); % How to superimpose a secondary axes on the second tile instead of the first tile?
l4 = plot(ax4,x2,y4,'-sg');
ax4.XAxisLocation = 'top';
ax4.YAxisLocation = 'right';
ax4.Color = 'none';
xlabel('Number of cycles'); ylabel('y4');
ax4.XAxis.Exponent = 0; xtickformat('%.0f');
axis square
legend([l3;l4],'y3','y4','Location','East');
ax3.Box = 'off';
ax4.Box = 'off';
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Axes Appearance finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
