列表的图形表示

skr*_*skr 6 wolfram-mathematica

说我有三个列表:a={1,5,10,15} b={2,4,6,8}c={1,1,0,1,0}.我想其中有一个情节ax轴线,b因为y轴和红/黑点标记1/0.对于.例如,坐标(5,4)将有一个红点.
换句话说,坐标(a[i],b[i])将有一个红色/黑色点,取决于c[i]是1还是0.
我一直在尝试我的手,ListPlot但无法弄清楚选项.

Mr.*_*ard 8

我建议这个.

a = {1, 5, 10, 15};
b = {2, 4, 6, 8};
c = {1, 1, 0, 1};

Graphics[
  {#, Point@{##2}} & @@@ 
    Thread@{c /. {1 -> Red, 0 -> Black}, a, b},
  Axes -> True, AxesOrigin -> 0
]
Run Code Online (Sandbox Code Playgroud)

Mathematica图形

或者更短但更混淆

Graphics[
  {Hue[1, 1, #], Point@{##2}} & @@@ Thread@{c, a, b}, 
  Axes -> True, AxesOrigin -> 0
]
Run Code Online (Sandbox Code Playgroud)


Dr.*_*ius 7

列昂尼德的想法,也许更天真.

f[a_, b_, c_] := 
 ListPlot[Pick[Transpose[{a, b}], c, #] & /@ {0, 1}, 
       PlotStyle -> {PointSize[Large], {Blue, Red}}]

f[a, b, c] 
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

编辑:只是为了好玩

f[h_, a_, b_, c_, opt___] := 
 h[Pick[Transpose[{a, b}], c, #] & /@ {0, 1}, 
  PlotStyle -> {PointSize[Large], {Blue, Red}}, opt]  

f[ ListPlot, 
   Sort@RandomReal[1, 100], 
   Sin[(2 \[Pi] #)/100] + RandomReal[#/100] & /@ Range[100], 
   RandomInteger[1, 100], 
      Joined -> True, 
      InterpolationOrder -> 2, 
      Filling -> Axis]
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


Leo*_*rin 6

以下是你的观点:

a = {1, 5, 10, 15};
b = {2, 4, 6, 8};
c = {1, 1, 0, 1};
Run Code Online (Sandbox Code Playgroud)

(我删除了最后一个元素c,使其长度与a和相同b).我建议用零和一个单独制作点的图像然后合并它们 - 这在这种情况下看起来最简单:

showPoints[a_, b_, c_] :=
With[{coords = Transpose[{a, b}]},
   With[{plotF = ListPlot[Pick[coords, c, #], PlotMarkers -> Automatic, PlotStyle -> #2] &},
     Show[MapThread[plotF, {{0, 1}, {Black, Red}}]]]]
Run Code Online (Sandbox Code Playgroud)

这是用法:

showPoints[a, b, c]
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


tom*_*omd 5

一种可能性:

ListPlot[List /@ Transpose[{a, b}], 
 PlotMarkers -> {1, 1, 0, 1} /. {1 -> { Style[\[FilledCircle], Red], 10}, 
   0 -> { { Style[\[FilledCircle], Black], 10}}}, 
 AxesOrigin -> {0, 0}]
Run Code Online (Sandbox Code Playgroud)

作为输出:

在此输入图像描述