How can I assign different color and width in a subplot?

조회 수: 7 (최근 30일)
Jonathan Bijman
Jonathan Bijman 2020년 1월 8일
편집: Cam Salzberger 2020년 1월 9일
Greetings dear community
I have a doubt. I need to get 3 subplot. Each line of the graph must have a specific color, a specific linestyle and a specific width.
I have this commands:
subplot(3,1,1)
x = linspace(0, 130, numel(T_A8_C));
X = [x;x].';
YA8 = [T_A8_C(:) T_A8_D(:)];
plot(X,YA8)
errA8=[T_desvA8_C(:) T_desvA8_D(:)];
errorbar(X,YA8,errA8);
hEBA8=errorbar(X,YA8,errA8);
hEB(1).Color=('red');
hEB(2).Color=('blue');
hEB(1).LineStyle=('-');
hEB(2).LineStyle=('-.');
hEB(1).LineWidth=(2);
xticks(0:5:130);
title('Cell Temperature Plot')
xlabel('Time (Days)')
ylabel('Cell Temperature (°C)')
legend('A8 Clean','A8 Dirty')
subplot(3,1,2)
YC5 = [T_C5_C(:) T_C5_D(:)];
plot(X,YC5)
errC5=[T_desvC5_C(:) T_desvC5_D(:)];
errorbar(X,YC5,errC5);
hEBC5=errorbar(X,YC5,errC5);
hEB(3).Color=('green');
hEB(4).Color=('purple');
hEB(3).LineStyle=('-');
hEB(4).LineStyle=('-.');
hEB(2).LineWidth=(2);
xticks(0:5:130);
xlabel('Time (Days)')
ylabel('Cell Temperature (°C)')
legend('C5 Clean','C5 Dirty')
subplot(3,1,3)
YE1 = [T_E1_C(:) T_E1_D(:)];
plot(X,YE1)
errE1=[ T_desvE1_C(:) T_desvE1_D(:)];
errorbar(X,YE1,errE1);
hEBE1=errorbar(X,YE1,errE1);
hEB(5).Color=('orange');
hEB(6).Color=('black');
hEB(5).LineStyle=('-');
hEB(6).LineStyle=('-.');
hEB(3).LineWidth=(2);
xticks(0:5:130);
xlabel('Time (Days)')
ylabel('Cell Temperature (°C)')
legend('E1 Clean','E1 Dirty')
But I only get only the colors red and blue, only one width and one line style.
How can I fix this?
Thank you so much!

답변 (1개)

Cam Salzberger
Cam Salzberger 2020년 1월 8일
"hEB" doesn't seem to be assigned in the code snippet you posted. You're assigning "hEBA8", "hEBC5", and "hEBE1", but not the hEB variable, which I assume should be an array of error bar objects. Maybe you meant to append hEBA8 and the rest to hEB after creation?
Instead of making the plots and then changing properties, can you pass the desired properties in as linespec or Name-Value arguments to the errorbar function?
-Cam
  댓글 수: 2
Jonathan Bijman
Jonathan Bijman 2020년 1월 8일
that is true. But I need T_A8_C in red, and segmented line whereas T_A8_D in blue and continuous line, Both of them are located in hEAB8. I do not know how can I get that
Cam Salzberger
Cam Salzberger 2020년 1월 9일
편집: Cam Salzberger 2020년 1월 9일
Plot them separately (two separate plot or errorbar commands), passing in the different linspec arguments for each. You can use "hold on" to get simple "plots" onto the same axes. I'm not as sure about errorbar plots, but I think it should work.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by