Same color for different subplots
8 views (last 30 days)
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 19 Sep 2023
"can you help me with that please?"
@Ale_798 Please check my answer below.
Answers (1)
Dyuman Joshi
on 11 Sep 2023
"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
0 Comments
See Also
Categories
Find more on Blue 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!