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!

回答(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 中查找有关 Line Plots 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by