Same color for different subplots
Show older comments

I want to plot some data in two subplots. To each datum are associated two parameters, which are the ones I'd like to plot, one for each subplot. I want the subplots to have the same color for the two parameters associated to the same datum, but different from the other ones, like in the picture. How can I do that?
3 Comments
Dyuman Joshi
on 11 Sep 2023
You can define a color array corresponding to the number of datums you have, and use indexing to access the colors while plotting the datums.
It will be better if you can attach the data you are working with, so we can provide a specific/definite solution.
Ale_798
on 11 Sep 2023
Dyuman Joshi
on 19 Sep 2023
"can you help me with that please?"
@Ale_798 Please check my answer below.
Answers (1)
"Then I need to define an array of 10 different colors:"
Yes.
RGB colors are a 3 element vectors with values in the range [0, 1].
There are multiple ways to do that.
1 - Manually defining colors. In the method, you have the choice of choosing which colors you want to use.
color = [0 0 0; %black
0 0 1; %blue
0 1 0; %green
0 1 1; %blue+green=cyan
1 0 0; %red
1 0 1; %red+blue=magenta
1 1 0; %rea+green=yellow
0.5 0.5 0.5; %gray
0.5 0 0; %maroon
0 0.5 0; %lime
]
n = 10;
color = rand(n,3)
color = (randi(256,n,3)-1)/255
3 - Using in-built colormaps in MATLAB
color = hsv(n)
You can check out the available colormaps here - https://in.mathworks.com/help/matlab/ref/colormap.html?s_tid=doc_ta#buc3wsn-1-map
Categories
Find more on Color and Styling 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!