필터 지우기
필터 지우기

Change the line color in subplot

조회 수: 36 (최근 30일)
Celia Clarke
Celia Clarke 2012년 7월 16일
댓글: Steven Lord 2021년 11월 8일
I am using a code to complete an anlyses and then produce 2 graphs using subplot. I have now set it up so it will plot a number of trials onto the same figure. However I would like to change the color or format of the lines so i can tell them apart. I see that this is ealiy done with plot(x,y,'r') however i do not know how i can code this when using a subplot.
Thanks for any help

답변 (2개)

C.J. Harris
C.J. Harris 2012년 7월 16일
An easier way might be to call 'hold all' after each subplot definition, and then just plot your values as normal. For example:
subplot(2,1,1)
hold all
plot(x1,y1)
plot(x2,y2)
plot(x3,y3)
hold off
subplot(2,1,2)
hold all
plot(x1,y1)
plot(x2,y2)
plot(x3,y3)
hold off

Jan
Jan 2012년 7월 16일
편집: Jan 2012년 7월 16일
A subplot is only a more powerful axes command, which allows a smarter setting of the position. You still have to create the diagram by plot or line, therefore I do not understand the question.
Please add the relevant part of your code by editing the question. Thanks.
Some guessing:
Axes1H = subplot(1,2,1);
Axes2H = subplot(1,2,2);
Line1H = plot(1:10, rand(1, 10), 'Parent', Axes1H);
Line2H = plot(3:12, rand(1, 10), 'Parent', Axes2H);
set(Line1H, 'LineColor', [1, 1, 0.5]);
set(Line2H, 'LineColor', [0.5, 1, 0.5]);
  댓글 수: 4
Rina Blomberg
Rina Blomberg 2021년 11월 8일
편집: Rina Blomberg 2021년 11월 8일
Thank you for such a quick reply. I list below my steps and hope this helps to isolate my problem.
  • I open the figure in matlab (via eeglab).
  • In the command line I tried both findall and findobj and got identical results:
>> allLinesInAxes = findall(gca, 'Type', 'line')
allLinesInAxes =
4×1 graphics array:
Line
Line
Line
Line
>> allLinesInAxes = findobj(gca, 'Type', 'line')
allLinesInAxes =
4×1 graphics array:
Line
Line
Line
Line
  • The 4x1 array corresponds to only one subplot (the "Cz" channel), which, when I apply the remainder of your code: set(allGreenLinesInNewAxes, 'Color', 'b') to the output above it successfully updates the green line in that subplot to blue (see attached screenshot)
Have I done something wrong or is there something more I need to do in order to "find" all 129 subplots and peform the same procedure on all?
Steven Lord
Steven Lord 2021년 11월 8일
When you call findobj with an axes handle as the first input, you find only objects in that axes and its descendants.
If you were to call findobj with a figure handle as the first input, you'd find only objects in that figure and its descendants.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by