2

As shown below, I have a graph. Inside each vertex point (i.e. circle) is a number. I prepare this graph as such. First I place a circle on the coordinates of each vertex using the following code:

plot(vertexCoords(1,:),vertexCoords(2,:),'o',...
  'MarkerFaceColor',[0.90 0.90 0.90],...
   'MarkerSize',30,'MarkerEdgeColor','k','LineWidth',2);

Then, I overlay a text object as follows:

text(vertexCoords(1,:),vertexCoords(2,:),num2cell(valueVector),...
    'HorizontalAlignment','center');

I would like to choose a certain colormap, and have the color of each circle be proportional to the number in the circle (the number can range from 0 to 1). How do I go about doing this?

enter image description here

4

1 回答 1

4

我认为您可以使用 scatter 命令而不是 plot 命令来执行此操作。请看下面...

% for random values
vertexCoords=rand([5 2]);
% for arbitrary values
valuevector=[4 5];

figure
% scatter(X,Y,S,C) where X,Y: coordinates, S:size (I set it to 500 here), C:Color
scatter(vertexCoords(1,:),vertexCoords(2,:),500,(valuevector), 'filled')
colormap(autumn)
hold on
text(vertexCoords(1,:),vertexCoords(2,:),num2cell(valuevector),...
'HorizontalAlignment','center');

于 2013-02-01T20:45:08.047 回答