Creating plot with double x axis

24 views (last 30 days)
Hi everyone,
I want to plot graph with two x axis. One is at the base level other one is at the uppermost level.
I plot u1 wrt y-axis also I want add u2 wrt to y-axis.
I write code below . How I add u2 datas as an second x-axis on the upper level ? Thanks for answer.
Simialr to this example
clear
clc
y = [2 3 4 5 6 7 8 9 10 15 20 25 30 40 50 60 80 100 150 200 280]
u1 =[6.76 7.11 7.48 7.79 8.03 8.30 8.49 8.72 8.91 9.70 10.16 10.44 10.53 10.71 10.76 10.81 10.90 11.0 11.07 11.1 11.02]
u2 =[19.0 18.1 17.0 16.2 15.8 15.4 15.1 14.4 14.1 12.8 13.2 12.5 11.8 11.1 10.5 10.5 9.3 9.2 8.5 7.9 7.3]
plot(u1,y,'p-','LineWidth',1,'Marker','square','LineStyle','none'); xlabel('u1 (m/s)'); ylabel('y (mm)');

Accepted Answer

David Hill
David Hill on 13 Dec 2021
Why not just use subplot?
subplot(2,1,1)
plot(u1,y)
subplot(2,1,2)
plot(u2,y)
  5 Comments
David Hill
David Hill on 14 Dec 2021
y = [2 3 4 5 6 7 8 9 10 15 20 25 30 40 50 60 80 100 150 200 280];
u1 =[6.76 7.11 7.48 7.79 8.03 8.30 8.49 8.72 8.91 9.70 10.16 10.44 10.53 10.71 10.76 10.81 10.90 11.0 11.07 11.1 11.02];
u2 =[19.0 18.1 17.0 16.2 15.8 15.4 15.1 14.4 14.1 12.8 13.2 12.5 11.8 11.1 10.5 10.5 9.3 9.2 8.5 7.9 7.3];
t=tiledlayout(1,1);
ax1=axes(t);
plot(ax1,u1,y,'-r','Marker','square','DisplayName','x = -100 mm');
ax2=axes(t);
plot(ax2,u2,y,'-k','Marker','o','DisplayName','x = +100 mm');
ax2.XAxisLocation='top';
ax2.Color = 'none';
ax1.XColor = 'r';
ylabel(ax1,'y (mm)');
xlabel(ax1,'u1 (m/s)');
xlabel(ax2,'u2 (m/s)');
xlim(ax1,[0 12]);
xlim(ax2,[0 20]);
legend(ax1,'Location','northwest');
legend(ax2,'Location', 'southwest');

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!