yyaxis automatically changes the linestyle and even inserts markers when plotting multiple lines. If you want to make the second plot appear as the first one, then I suggest you use yyaxis but hide one of the axes.
yyaxis left
plot(rand(10,10))
yyaxis right
set(gca,'ycolor','none')
You could also grab the default settings of the yyaxis in your first graph
cs=get(gca,'colororder');
ls=get(gca,'linestyleorder')
ans =
7×2 char array
'- '
'--'
': '
'-.'
'o-'
'^-'
'*-'
and then simply apply them after toggling to your second graph
set(gca,'linestyleorder',ls)
set(gca,'colororder',cs)
Note that the yyaxis by default only has one colororder and multiple linestyleorders, whereas the normal plot has one linestyleorder and multiple colororders. By default, the first linestyle is plotted with each color, then the second linestyle is plotted with each colors and so on... This behaviour is controlled by the colororderindex and linestyleindex.
Best Answer