在Mathematica 8中标记同一图表中的不同图

时间:2012-09-14 14:26:16

标签: wolfram-mathematica mathematica-8

我在 Mathematica 中标注了一个情节。我会描述我的问题。

我有这样的功能。

y = 4 x / L + 2

我想绘制y与x的关系图。而且,我有

L={10,20,30,40}

当我写下面的代码时,

Plot[y, {x, 0, 100}, 
    ImageSize -> Scaled[1.0], PlotLabel ->  Style["y vs X ", FontSize -> 18]]

我在同一个图表中有四个不同的图表。我想知道如何用相关L值标记每个图。

2 个答案:

答案 0 :(得分:4)

根据我之前的帖子here,您可以根据需要使用此方法标记线条。标记后,可以将没有动态内容的图设置为plainplot

通过将每一行转换为自我标记按钮来工作。您可以修改labels以获取不同的标签。

l = {10, 20, 30, 40};
y[x_, s_] := 4 x/s + 2

plot = Plot[Evaluate@Table[y[x, u], {u, l}], {x, 0, 100},
   PlotLabel -> Style["y vs X ", FontSize -> 18]];

pos = Position[plot, _Line];
Array[(line[#] = plot[[Sequence @@ pos[[#]]]]) &, Length@l];
AddLabel[label_] := Module[{},
  AppendTo[plot[[1]], Inset[Framed[label, Background -> White], pt]];
  (* Removing buttons for final plot *)
  plainplot = plot;
  Array[
   (plainplot[[Sequence @@ pos[[#]]]] =
      plainplot[[Sequence @@ Append[pos[[#]], 1]]]) &, Length@l]]
labels = ToString /@ l;
Array[
  (plot[[Sequence @@ pos[[#]]]] =
     Button[line[#], AddLabel[labels[[#]]]]) &, Length@l];
Dynamic[EventHandler[plot,
  "MouseDown" :> (pt = MousePosition["Graphics"])]]

enter image description here

答案 1 :(得分:3)

l = {10, 20, 30, 40}
y[x_, s_] := 4 x/s + 2
<< PlotLegends`

Plot[Evaluate@Table[y[x, u], {u, l}], {x, 0, 100}, 
 ImageSize -> Scaled[1.0], 
 PlotLabel -> Style["y vs X ", FontSize -> 18], 
 PlotLegend -> ("L = " <> ToString@# & /@ l)]

Mathematica graphics

相关问题