필터 지우기
필터 지우기

how to format a graph so that data point varies if..............

조회 수: 4 (최근 30일)
William Hou
William Hou 2021년 2월 2일
편집: Jack Shannon 2021년 2월 2일
so I have a data set of 3 vectors and I am plotting x vz y. I want to vary the color of the data point based on the value of z. Any ideas as to how to do this?
z=[0,1,2,3]
x=[5.1,8.2,2,3]
x=[2.5,4.9,8,4]

답변 (2개)

Adam Danz
Adam Danz 2021년 2월 2일

Jack Shannon
Jack Shannon 2021년 2월 2일
편집: Jack Shannon 2021년 2월 2일
Plots have an option to set the color using either a string or an RGB triplet. You can get the default color order for a figure using the syntax get(gca,'colororder'). You can reset this color order, but if you want to manually control the color of each element of your figure it's best to get/create your color order and then explicitly set the color of each plot you make.
Not sure this is what you're looking for, but here's a simple example. You have two different values of x, so I'll just use the second one:
z=[0,1,2,3];
% x=[5.1,8.2,2,3];
x=[2.5,4.9,8,4];
figure(1);
colors = get(gca,'colororder'); % matrix where each row is an RGB triplet
hold on
plot(z,x,'k-') % plot your data
for i = 1:numel(z) % loop over values of z
plot(z(i),x(i),'o',... % create a marker at point i
'color',colors(i,:),... % set the color of the marker border
'MarkerFaceColor',colors(i,:)); % set the face color of the marker
end
This creates the following plot:

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by