plot 2 different time data on the same axis in same graph
Mostra commenti meno recenti
I have 2 dataset to plot both wrt to time axis in the same plot but time data is different for both the data. on yaxis 1 I want DATA1(line) on yaxis 2 i want DATA2(buuble markers) how can i do so. I am attaching the data file
2 Commenti
Walter Roberson
il 29 Gen 2021
See yyaxis left and yyaxis right
Abhijit Sardar
il 29 Gen 2021
Risposta accettata
Più risposte (2)
J. Alex Lee
il 29 Gen 2021
0 voti
or potentially you are just looking for "hold on"
1 Commento
Abhijit Sardar
il 29 Gen 2021
T = readtable('TIMEDATA.txt');
yyaxis right
plot(T.TIME2, T.DATA2, 'Displayname', 'DATA2')
yyaxis left
plot(T.TIME1, T.DATA1, 'Displayname', 'DATA1')
legend show
1 Commento
You might notice that is not very useful. The reason is that you used a single x axes even though the x values are fairly different.
T = readtable('TIMEDATA.txt');
fig = gcf;
ax1 = axes(fig);
h(1) = line(ax1, T.TIME1, T.DATA1, 'Displayname', 'DATA1', 'color', 'k');
legend(h(1), 'Location', 'northwest')
ax1_pos = ax1.Position; % position of first axes
ax2 = axes('Position',ax1_pos,...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none');
h(2) = line(T.TIME2, T.DATA2, 'parent', ax2, 'Displayname', 'DATA2', 'color', 'b');
legend(h(2), 'Location', 'northeast')
Unfortunately in order to get the axes in the right location, it becomes a challenge to get a merged legend.
Categorie
Scopri di più su Graphics Object Properties in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


