2012-09-14 24 views
3

我有一個問題,在Mathematica中標註了一個圖塊。我會描述我的問題。Mathematica 8在同一圖表中標記不同的圖塊

我有這樣的功能。

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值來標記每個情節。

+0

請閱讀使用說明書,以獲取有關語法 –

回答

4

您可以標記線,你喜歡使用這種方法的基礎上,我先前的職位here。標記後,沒有動態內容的情節可以被設置爲plainplot

它通過將每一行變成一個自我貼標籤按鈕來工作。您可以修改labels以獲得不同的標籤。

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

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

pos = Position[plot, _Line]; 
Array[(line[#] = plot[[Sequence @@ pos[[#]]]]) &, [email protected]]; 
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]]]) &, [email protected]]] 
labels = ToString /@ l; 
Array[ 
    (plot[[Sequence @@ pos[[#]]]] = 
    Button[line[#], AddLabel[labels[[#]]]]) &, [email protected]]; 
Dynamic[EventHandler[plot, 
    "MouseDown" :> (pt = MousePosition["Graphics"])]] 

enter image description here

+0

http://mathematica.stackexchange.com/a/4028/193和http://mathematica.stackexchange.com/questions/4444/labeling-individual-curves-in-mathematica和 –

+0

非常感謝Mr. Wizard先生。你能告訴我如何給他們貼上標籤,例如「l = 10」,....我想刪除這些小盒子。我是Mathematica的初學者。非常感謝你對此的幫助。 – TMH

+0

@Thakshila - 您可以將Inset設置爲Inset [Framed [「l =」<> ToString [label],Background - > White,FrameStyle - > None],pt]'或(將標籤移動到統一的位移)Inset [「l =」<> ToString [標籤] <>「\ n」,pt]' –

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

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

Mathematica graphics

+0

+1的繪圖功能,我在我的答案使用基本的抓地力,TA。 –

+0

謝謝belisarius。當我打印這個圖時,其他人看不到顏色。這就是問題所在。 – TMH

相關問題