有没有办法在mathematica中绘制一组具有相同原点的线?

时间:2011-09-25 17:26:10

标签: wolfram-mathematica

我有一个由这个列表给出的一组点:

list1 = {{3, 1}, {1, 3}, {-1, 2}, {-1, -1}, {1, -2}};

我希望Mathematica从原点到上面的所有点绘制一条线。换句话说,从原点(0,0)到上述集合中的所有单个点绘制矢量。有没有办法做到这一点?到目前为止,我已经尝试了Filling选项PlotPointsVectorPlot,但他们似乎无法做我想做的事情。

2 个答案:

答案 0 :(得分:12)

轻松开始,然后增加难度:

Graphics[{Arrow[{{0, 0}, #}] & /@ list1}]

enter image description here

Graphics[{Arrow[{{0, 0}, #}] & /@ list1}, Axes -> True]

enter image description here

Needs["PlotLegends`"];
list1 = {{3, 1}, {1, 3}, {-1, 2}, {-1, -1}, {1, -2}};
k = ColorData[22, "ColorList"][[;; Length@list1]];

GraphicsRow[{
    Graphics[Riffle[k, Arrow[{{0, 0}, #}] & /@ #], Axes -> True], 
    Graphics@Legend[Table[{k[[i]], #[[i]]}, {i, Length@#}]]}] &@list1

enter image description here

Needs["PlotLegends`"];
list1 = {{3, 1}, {1, 3}, {-1, 2}, {-1, -1}, {1, -2}};
k = ColorData[22, "ColorList"][[;; Length@list1]];
ls = Sequence[Thick, Line[{{0, 0}, {1, 0}}]];

GraphicsRow[{
    Graphics[Riffle[k, Arrow[{{0, 0}, #}] & /@ #], Axes -> True], 
    Graphics@Legend[MapThread[{Graphics[{#1, ls}], #2} &, {k, #}]]}] &@list1

enter image description here

Needs["PlotLegends`"];
list1 = {{3, 1}, {1, 3}, {-1, 2}, {-1, -1}, {1, -2}};
pr = {Min@#, Max@#} & /@ Transpose@list1;
k = ColorData[22, "ColorList"][[;; Length@list1]];

GraphicsRow[{
    Graphics[r = Riffle[k, {Thick,Arrow[{{0, 0}, #}]} & /@ #], Axes -> True], 
    Graphics@
     Legend[MapThread[
             {Graphics[#1, Axes -> True, Ticks -> None, PlotRange -> pr], 
              Text@Style[#2, 20]} &, 
             {Partition[r, 2], #}]]}] &@list1

enter image description here

你也可以调整ListVectorPlot,虽然我不明白为什么你应该这样做,因为它不打算像这样使用:

list1 = {{3, 1}, {1, 3}, {-1, 2}, {-1, -1}, {1, -2}};
data = Table[{i/2, -i/Norm[i]}, {i, list1}];
ListVectorPlot[data, VectorPoints -> All, 
                     VectorScale  -> {1, 1, Norm[{#1, #2}] &}, 
                     VectorStyle  -> {Arrowheads[{-.05, 0}]}]

enter image description here

答案 1 :(得分:6)

Graphics[
 {
  Line[{{0, 0}, #}] & /@ list1
  }
 ]

enter image description here

其中/@是函数Map的简写中缀表示法。

我想知道你为什么尝试FillingPlotpointsVectorPlot。我必须假设你根本没有阅读过这些文档,因为即使是肤浅的阅读也会告诉你这些命令和选项与你正在寻找的功能无关。