Change the line color in subplot
80 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(2 个)
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
0 个评论
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
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
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 Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!