Creating plot with double x axis

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)');

 Risposta accettata

Why not just use subplot?
subplot(2,1,1)
plot(u1,y)
subplot(2,1,2)
plot(u2,y)

5 Commenti

No I need both u1 and u2 on the same graph.
David Hill
David Hill il 13 Dic 2021
Modificato: David Hill il 13 Dic 2021
t=tiledlayout(1,1);
ax1=axes(t);
plot(ax1,u1,y,'-r','Marker','square');
ax2=axes(t);
plot(ax2,u2,y,'-k','Marker','o');
ax2.XAxisLocation='top';
ax2.Color = 'none';
ax1.XColor = 'r';
jack london
jack london il 14 Dic 2021
Modificato: jack london il 14 Dic 2021
How I add legend as an u1 and u2.
I also add u1 and u2 as an both x axis label and y axis label as a y(mm)
As a last I want to start both x axis from 0 and puting legend in this space as in example above.
Thank you very much!
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');
Thank you so much!

Accedi per commentare.

Più risposte (0)

Categorie

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by