使用Mathematica中的图形进行条件着色

3
请考虑:
dalist = {{1, 1, 1}, {2, 2, 2}, {3, 3, 3}, {4, 4, 4}, {5, 5, 5}, 
          {1, 2, 1}, {2, 3, 1}, {3, 4, 1}, {4, 5, 1}, {5, 6, 1}}

我使用以下代码绘制上述图形,其中#2#3分别代表x和y坐标。
Graphics@MapThread[Point[{#2, #3}] &, Transpose@dalist]

图片描述

  • #1 是我的数据中想要用来给点着色的时间参考。

  • 它可以在1到30之间变化。

  • #1 = 1 应该始终产生相同的颜色。

编辑:在下面的解决方案基础上进行改进

  • 如何手动设置颜色范围/渐变或使用现有的颜色范围(“BlackBodySpectrum”)?
3个回答

2
您可以使用 ColorData
Graphics@MapThread[{ColorData[1][#1], Point[{#2, #3}]} &, 
  Transpose@dalist]

2

尝试:

datlist = Flatten[Table[{i, j + i, j}, {i, 1, 20}, {j, 1, 20}], 1];
colordata = 60; (* Try different palettes 1 .. 62 *)

Graphics[(Sequence @@ 
     {Directive[ 
      ColorData[colordata][Mod[#[[1]], ColorData[colordata, "Range"][[2]]]]], 
     PointSize -> Large, Point[{#[[2]], #[[3]]}]} & /@ datlist), 
     Frame -> True]

输入图像描述

编辑

使用BlackBodySpectrum

datlist = Flatten[Table[{i, j + i, j}, {i, 1, 20}, {j, 1, 20}], 1];
colordata = "BlackBodySpectrum";(*Try different palettes 1.. 62*)
Graphics[(
  Sequence @@ {Directive[
       ColorData[
         colordata][#[[1]] ColorData[colordata, 
            "Range"][[2]]/(Length@datlist/
            Length@Select[datlist, #[[1]] == 1 &])]], 
      PointSize -> Large, Point[{#[[2]], #[[3]]}]} & /@ datlist), 
 Frame -> True]

enter image description here


2

不需要使用MapThread

Graphics[{PointSize -> 0.05, {ColorData[1][#1], Point[{#2, #3}]} & @@@dalist}]

在此输入图片描述

你可以使用Blend来创建自己的图像渐变:

Graphics[{PointSize -> 0.05, 
         {Blend[{Red, Yellow, Blue}, #1/5], Point[{#2, #3}]} & @@@ dalist}]

请注意,您需要自行处理数据范围的缩放,使得最大值为1,最小值为0(如果您想要最优地利用可用范围)。 enter image description here

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接