How can I assign different color and width in a subplot?
조회 수: 6 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
답변 (1개)
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
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 Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!