【问题标题】:Incorporating color into graphical representation in Matlab在 Matlab 中将颜色合并到图形表示中
【发布时间】:2013-02-01 18:02:46
【问题描述】:

如下图,我有一个图表。每个顶点(即圆)内部都有一个数字。 我准备这个图表。首先,我使用以下代码在每个顶点的坐标上放置一个圆:

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

然后,我如下覆盖一个文本对象:

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

我想选择某个colormap,并让每个圆圈的颜色与圆圈中的数字成正比(数字可以从0到1)。我该怎么做?

【问题讨论】:

    标签: matlab plot color-mapping


    【解决方案1】:

    我认为您可以使用 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');

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-05
      • 1970-01-01
      • 2015-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-28
      • 2015-02-03
      相关资源
      最近更新 更多