Change the line color in subplot
80 views (last 30 days)
Show older comments
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 Comments
Answers (2)
C.J. Harris
on 16 Jul 2012
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 Comments
Jan
on 16 Jul 2012
Edited: Jan
on 16 Jul 2012
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 Comments
Rina Blomberg
on 8 Nov 2021
Edited: Rina Blomberg
on 8 Nov 2021
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
on 8 Nov 2021
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.
See Also
Categories
Find more on Subplots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!