MATLAB Answers

Subplot VAR variables in one figure

26 views (last 30 days)
kevin joe cecere palazzo
kevin joe cecere palazzo on 6 Aug 2020
Commented: Vasishta Bhargava on 11 Aug 2020
I have generated a m-dimensional (m=5) sample of T observations, from a VAR model of lag order p. I want to generate one figure with m subplots, each for every variable in the sample. I have found and copied this code, but an error occurs: the first times, problem with axes properties occurred ("--- is not a valid axes line style", something like this), now it just crashes. How could I do what I would like to do?
Y=Y(:,p+1:end); %Y is the mXT matrix containing the m-dimensional sample.
FS=15;
LW=2;
gr_size2=ceil(m/3);
figure(1)
set(0,'DefaultAxesColorOrder',[0 0 1],...
'DefaultAxesLineStyleOrder','-|-|-')
set(gcf,'Color',[1 1 1])
set(gcf,'defaultaxesfontsize',FS)
for k=1:m
subplot(gr_size2,2,k)
plot(Y(k,:),'b','Linewidth',LW)
title(sprintf('Y_%d',k))
end

  4 Comments

Show 1 older comment
kevin joe cecere palazzo
kevin joe cecere palazzo on 10 Aug 2020
Error using axes
The value '---' is not a valid line style.
Error in subplot (line 591)
ax = axes('Units', 'normalized', 'Position', position, ...
Vasishta Bhargava
Vasishta Bhargava on 10 Aug 2020
The argument of the default line style is not correct
Try using only '-' without any | dashes
Vasishta Bhargava
Vasishta Bhargava on 11 Aug 2020
Try using only '-' without any | dashes
It should work

Sign in to comment.

Answers (3)

Vasishta Bhargava
Vasishta Bhargava on 10 Aug 2020
Edited: Vasishta Bhargava on 10 Aug 2020
Try using '--' without a '|'between the dashes in the defaultaxeslinestyleorder

  0 Comments

Sign in to comment.


Sudheer Bhimireddy
Sudheer Bhimireddy on 10 Aug 2020
I just tried your code with a dummy matrix, values and see no error regarding linestyle. It would help if you can attach your matrix.
Z = peaks;
m = 6;
gr_size2=ceil(m/3);
figure(1)
set(0,'DefaultAxesColorOrder',[0 0 1],...
'DefaultAxesLineStyleOrder','-|-|-');
set(gcf,'Color',[1 1 1])
set(gcf,'defaultaxesfontsize',FS)
for k=1:6
subplot(3,3,k)
plot(Z(k,:),'b','Linewidth',LW)
title(sprintf('Y_%d',k))
end

  0 Comments

Sign in to comment.


Monisha Nalluru
Monisha Nalluru on 11 Aug 2020
Edited: Monisha Nalluru on 11 Aug 2020
The error is caused due to call of axes after setting the 'defaultAxesLineStyleOrder' to -|-|-.
This issue is fixed from 2019b.
As a workaround if you are using release earlier R2019b you may use below command
set(0,'defaultAxesColorOrder',[0 0 1],'defaultAxesLineStyleOrder','-');
Also, in the question mentioned above, you wanted to create m-subplot but in the code your are not plotting m-subplot this may affect the result.
Refer the subplot documentation

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by