plot 2 different time data on the same axis in same graph
Mostrar comentarios más antiguos
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 comentarios
Walter Roberson
el 29 de En. de 2021
See yyaxis left and yyaxis right
Abhijit Sardar
el 29 de En. de 2021
Respuesta aceptada
Más respuestas (2)
J. Alex Lee
el 29 de En. de 2021
0 votos
or potentially you are just looking for "hold on"
1 comentario
Abhijit Sardar
el 29 de En. de 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 comentario
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.
Categorías
Más información sobre Graphics Object Properties en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


