使用Mathematica中的图形替换十字架的磁盘

时间:2011-06-25 12:13:58

标签: graphics wolfram-mathematica

考虑以下列表:

dalist = {{47.9913, 11.127, 208}, {47.5212, 10.3002, 208}, 
          {49.7695, 9.96838, 160}, {48.625, 12.7042, 436}}

这些是屏幕上眼睛注视的坐标,在每个子列表中

#1是X坐标,

#2 Y坐标和

#3,在该特定位置花费的持续时间

然后我使用以下内容:

Disk[{#[[1]], #[[2]]}, 3N[#[[3]]/Total[dalist[[All, 3]]]]] & /@ dalist

绘制持续时间加权直径的磁盘。

我想绘制十字形而不是两个段在它们的中间相交,每个段的长度等于圆盘直径,如下图所示。

enter image description here

这就是我所拥有的:

Graphics[{
          Line[{{#[[1]] - 3 N[#[[3]]/Total[dalist[[All, 3]]]], #[[2]]},
                {#[[1]] + 3 N[#[[3]]/Total[dalist[[All, 3]]]], #[[2]]}}] & /@ dalist,
          Line[{{#[[1]], #[[2]] - 3 N[#[[3]]/Total[dalist[[All, 3]]]]},
                {#[[1]], #[[2]] + 3 N[#[[3]]/Total[dalist[[All, 3]]]]}}] & /@ dalist}]

我想知道是否有更简单的方法,使用类似于ListPlot中存在的PlotMarkers

5 个答案:

答案 0 :(得分:4)

使用两行。类似的东西:

pointTrans =
  {
     Line[{{#[[1]] - l, #[[2]]}, {#[[1]] + l, #[[2]]}}],
     Line[{{#[[1]], #[[2]] - l}, {#[[1]], #[[2]] + l}}]
     } /. l -> #[[3]]/Mean[dalist[[All, 3]]] &;

pointTrans /@ dalist // Graphics // Show

答案 1 :(得分:3)

由于你已经可以绘制圆圈,为什么不这样使用它:

circles=Graphics[Disk[{#[[1]], #[[2]]}, 3 N[#[[3]]/Total[dalist[[All, 3]]]]] & /@ dalist]

enter image description here

然后

circles /. Disk[{x_, y_}, r_] :> Line[{{{x, y - r/2}, {x, y + r/2}}, {{x - r/2, y}, {x + r/2, y}}}]

enter image description here

答案 2 :(得分:3)

我认为这里的辅助功能很方便:

makeCross[{x_, y_, r_}, total_] := With[{scale = 3*r/total}, 
  Line[{{{x - scale, y}, {x + scale, y}}, {{x, y - scale}, {x, y + scale}}}]]

total = Total[dalist[[All, 3]]];

Graphics[makeCross[#, mean] & /@ dalist]

答案 3 :(得分:3)

您也可以使用BubbleChart

plus[{x:{x0_, x1_}, y:{y0_, y1_}}, __] := 
 Line[{{{x0, Mean[y]}, {x1, Mean[y]}}, {{Mean[x], y0}, {Mean[x], y1}}}]

BubbleChart[dalist, ChartElementFunction -> plus] (*or maybe "MarkerBubble" instead of plus*)

enter image description here

答案 4 :(得分:1)

我想提供Artefacto代码的修改。

pointTrans = 
  With[{l = #3/2/Mean@dalist[[All, 3]]}, 
    Line@{{{# - l, #2}, {# + l, #2}}, {{#, #2 - l}, {#, #2 + l}}}
  ] &;

Graphics[{Thick, pointTrans @@@ dalist}]

enter image description here