Same color for different subplots
이전 댓글 표시

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
Dyuman Joshi
2023년 9월 11일
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
2023년 9월 11일
Dyuman Joshi
2023년 9월 19일
"can you help me with that please?"
@Ale_798 Please check my answer below.
답변 (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
카테고리
도움말 센터 및 File Exchange에서 Color and Styling에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!