How do I make a plot with specific RGB color values for each marker from the same data set?
이전 댓글 표시
If I have an x and y vector and want to plot them with a specific RGB color value, how would I do that? Ideally, I would like to have a matrix of color values that would coincide with the x and y values. In addition, I was hoping to define x values with something like x=(-50:0.004:50) but I couldn't get MATLAB to plot the corresponding y and color values correctly.
I was initially thinking about using a for loop with hold on and plotting each data point separately, but that significantly slows down MATLAB when you have a lot of data points.
Here's a simplified example of the plot I am hoping to make.
hold on
vrty=50; %number of data points
colors=[hsv(vrty)]; %Defined colors I want to use
for i=1:vrty %loops figure until done with points
x=i;
y=cos(x*pi/vrty);
h=plot(x,y,'o');
cmatrix_size=size(colors);
color=colors((i),:);
set(h,'MarkerEdgeColor','none','MarkerSize',4,'MarkerFaceColor',color)
end
답변 (1개)
Chad Greene
2014년 6월 20일
1 개 추천
The scatter function accepts rgb color values corresponding to each point. It'll help you avoid using a loop.
댓글 수: 2
Chad Greene
2014년 6월 20일
Here's the code:
colors=[hsv(vrty)];
scatter(1:50,cos((1:50)*pi/50),30,colors,'filled')
Chad Greene
2014년 6월 20일
On a side note, as an alternative to the hsv color map, you can use rgbmap. I've included your example in the documentation file.
카테고리
도움말 센터 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!