【问题标题】:MATLAB plot point with color based on distance from line基于与线距离的颜色的 MATLAB 绘图点
【发布时间】:2016-12-12 17:46:38
【问题描述】:

我在 MATLAB 中有一组m 点和一组n 二维线。假设n 线以n 颜色绘制,我需要用最接近的一组线的 平均颜色 的颜色绘制每个点。我可以计算点到线的距离,但是如何使用scatter 将点的颜色设置为由最接近的线的距离加权的值?

【问题讨论】:

  • 给每一行一个整数标志,然后将其用作Cscatter 的索引。
  • 这不会根据与线的距离绘制带有颜色的点,它不应该涉及使用与线的距离来确定颜色吗?我还要提一下,点和线的数量是不同的。
  • 你能发个minimal reproducible example吗?
  • 根据您已经计算的最接近的行给每一行一个整数标志,然后将其用作Cscatter 索引。例如。最接近底线的所有点都获得标志1,最接近第二行的所有点都获得标志2 等。您可以使用该列作为C 输入来分散点的颜色。 (抱歉,我错过了第一条评论中的标志)

标签: matlab scatter-plot scatter


【解决方案1】:

这个例子应该对你有帮助:

clear all;
close all;

m = 20; %number of points
markerSize = 25;

%example points
a=rand(2,m);
a(:,m-1) = [0;0]; % this point will be purple
a(:,m-2) = [1;0]; % this point will be blue
a(:,m-3) = [0;1]; % this point will be red

%line x=0 is red
%line y=0 is blue;
f1 =figure(1);
hold on;
for i = 1:m
    pointColor = [1-a(1,i) 0 1-a(2,i)]; % rgb format - calculate distance here
    % [0 0 0] - black , [1 1 1] - white
    % pointColor=(lineColor1*distance1 + lineColor2*distance2+...)/numberOfClosestLines;
    scatter(a(1,i),a(2,i),markerSize, pointColor)
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-03
    • 1970-01-01
    • 2018-04-08
    • 1970-01-01
    • 2012-01-23
    相关资源
    最近更新 更多