Вопрос

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

Это было полезно?

Решение

I think you can do this with the scatter command instead of plot command. Please see below...

% 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');

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top