2011-08-08 28 views
9

通常我必須同時可視化多個數據集,通常在ListPlot或其Log-companions中。由於數據集的數量通常大於容易區分的線條樣式的數量,並且創建大量的情節圖例仍然有些不妥協,所以我仍在尋找一種在我的地塊中註釋不同線條/集合的好方法。工具提示在屏幕上工作時很好,但如果我需要摳圖,他們無法幫助。如何在ListPlots中註釋多個數據集

最近,我與網格選項枚舉我的數據集起到了一圈,發現了一些奇怪的東西

GraphicsGrid[Partition[Table[ListPlot[ 
[email protected] 
Table[{Sin[x], Cos[x], Tan[x], Cot[x]}, {x, 0.01, 10, 0.1}], 
PlotMarkers -> {"1", "2", "3", "4"}, Mesh -> i, Joined -> True, 
PlotLabel -> "Mesh\[Rule]" <> ToString[i], ImageSize -> 180], {i, 
1, 30}], 4]] 

結果看起來像這樣我的機器上(Windows 7的64位,數學8.0.1):

 Mesh = i, with i running from 1 to 30

有趣的是,對於網格 - > 2,8和10,結果看起來像我預期的那樣,其餘的則不然。我不明白Mesh選項,或者它不理解我。

這裏是我的問題:

  1. 是網格ListPLot竊聽或我錯誤地使用它?
  2. 我該如何移動連續集合的網格點以避免疊印?
  3. 你有任何其他建議如何註釋/枚舉一個情節中的多個數據集?
+3

Mesh'和''之間的相互作用的PlotMarkers'在上來的問題[本SO問題](http://stackoverflow.com/questions/4789047/custom-intervals-of-markers-在-數學-plotmarkers/4790805#4790805)。我當時向世界資源研究所報告,技術支持將其轉交給開發小組審視。希望它會在下一個版本中得到修復。 – Simon

+1

我很好奇爲什麼有些網格選項可以工作,而其他許多選項則不能。 –

+2

至於你的第三個問題,你可能想看看我在這裏使用的圖:http://stackoverflow.com/questions/5745298/how-do-i-access-the-stackoverflow-api-from-mathematica/5745783 #5745783。這涉及手動註釋(可以使其半自動工作)。我覺得最終結果在視覺上比許多其他方法更令人滿意。 –

回答

12

你可以嘗試沿着這些線。使每一行成爲一個按鈕,點擊後即可識別自己。

plot=Plot[{Sin[x],Cos[x]},{x,0,2*Pi}]; 
sinline=plot[[1,1,3,2]]; 
cosline=plot[[1,1,4,2]]; 
message=""; 
altplot=Append[plot,PlotLabel->Dynamic[message]]; 
altplot[[1,1,3,2]]=Button[sinline,message="Clicked on the Sin line"]; 
altplot[[1,1,4,2]]=Button[cosline,message="Clicked on the Cos line"]; 
altplot 

如果添加事件處理程序,你可以得到你點擊的位置,並與相關定位標籤的情節添加插圖。以動態方式包裹情節,以便在每次點擊按鈕後自行更新。它工作正常。

在迴應評論,這裏是一個更全面的版本:

plot = Plot[{Sin[x], Cos[x]}, {x, 0, 2*Pi}]; 
sinline = plot[[1, 1, 3, 2]]; 
cosline = plot[[1, 1, 4, 2]]; 
AddLabel[label_] := (AppendTo[plot[[1]], 
    Inset[Framed[label, Background -> White], pt]]; 
    (* Remove buttons for final plot *) 
    plainplot = plot; 
    plainplot[[1, 1, 3, 2]] = plainplot[[1, 1, 3, 2, 1]]; 
    plainplot[[1, 1, 4, 2]] = plainplot[[1, 1, 4, 2, 1]]); 
plot[[1, 1, 3, 2]] = Button[sinline, AddLabel["Sin"]]; 
plot[[1, 1, 4, 2]] = Button[cosline, AddLabel["Cos"]]; 
Dynamic[EventHandler[plot, 
    "MouseDown" :> (pt = MousePosition["Graphics"])]] 

添加就行了標籤點擊。最終的註釋圖表設置爲'plainplot',可打印和可複製,並且不包含動態元素。

[當天晚些時候]另一個版本,這次是通用的,並基於初始圖表。 (使用Mark McClure解決方案的一部分。)對於不同的圖,可以根據需要編輯'ff'和'spec'。

ff = {Sin, Cos, Tan, Cot}; 
spec = Range[0.1, 10, 0.1]; 
(* Plot functions separately to obtain line counts *) 
plots = Array[ListLinePlot[ff[[#]] /@ spec] &, [email protected]]; 
plots = DeleteCases[plots, Line[_?(Length[#] < 3 &)], Infinity]; 
numlines = Array[[email protected][plots[[#]], Line[_], Infinity] &, 
    [email protected]]; 
(* Plot functions together for annotation plot *) 
plot = ListLinePlot[#@spec & /@ ff]; 
plot = DeleteCases[plot, Line[_?(Length[#] < 3 &)], Infinity]; 
lbl = [email protected][ConstantArray[[email protected][[#]], 
     numlines[[#]]] &, [email protected]]; 
(* Line positions to substitute with buttons *) 
linepos = Position[plot, Line, Infinity]; 
Clear[line]; 
(* Copy all the lines to line[n] *) 
Array[(line[#] = plot[[Sequence @@ [email protected][[#]]]]) &, 
    [email protected]]; 
(* Button function *) 
AddLabel[label_] := (AppendTo[plot[[1]], 
    Inset[Framed[label, Background -> White], pt]]; 
    (* Remove buttons for final plain plot *) 
    plainplot = plot; 
    bpos = Position[plainplot, Button, Infinity]; 
    Array[(plainplot[[Sequence @@ [email protected][[#]]]] = 
     plainplot[[Sequence @@ Append[[email protected][[#]], 1]]]) &, 
    [email protected]]); 
(* Substitute all the lines with line buttons *) 
Array[(plot[[Sequence @@ [email protected][[#]]]] = Button[line[#], 
     AddLabel[lbl[[#]]]]) &, [email protected]]; 
Dynamic[EventHandler[plot, 
    "MouseDown" :> (pt = MousePosition["Graphics"])]] 

下面是它的外觀。註釋之後,可以將純圖形對象設置爲'plainplot'變量。

Annotated Chart

+2

非常有趣的介紹!對於工具提示來說,這是一個不錯的選擇(特別是如果該行將以某種方式突出顯示,例如將會變成粗體 - 我們不需要點擊它,只需將鼠標放在它上面!)。謝謝。 +1 –

+0

非常好的想法,但是,它類似於Tooltip,如果你需要打印的情節,這往往是無用的。雖然介紹,這是一個很好的方法。 –

+3

@ Markus - 我已經添加了一個更完整的示例,它在放置標籤後顯示標籤,因此可以打印帶註釋的圖。 –

8

一種方法是單獨生成圖,然後將它們一起顯示。由於PlotMarkers似乎在處理一個數據集時會發揮我們預期的效果,所以這會產生更像您的其他帖子的代碼。我們可以使用ColorDataPlotStyle獲得相同的顏色。這裏的結果:

ff = {Sin, Cos, Tan, Cot}; 
plots = Table[ListLinePlot[ff[[i]] /@ Range[0.1, 10, 0.1], 
    PlotStyle -> {ColorData[1, i]}, 
    PlotMarkers -> i, Mesh -> 22], {i, 1, Length[ff]}]; 
(* Delete the spurious asymptote looking thingies. *) 
plots = DeleteCases[plots, Line[ll_?(Length[#] < 4 &)], Infinity]; 
Show[plots, PlotRange -> {-4, 4}] 

enter image description here

+0

+1,這是我使用的方法,因爲有時您需要使用符號和顏色來跟蹤幾個額外的維度,並且沒有什麼效果。 – rcollyer

+0

我知道將上面的例子分解成單獨的個體情節是一個解決方法 - 也許這是一條路。 –

4

你要密謀可計算的曲線或實際數據?

如果它是可計算的曲線,那麼通常使用plot legend (key)。 您可以使用不同的寬度和粗細來區分灰度打印機上的線條。 PlotLegends文檔中有很多示例。

如果它是真實數據,那麼通常數據很稀疏,您可以使用PlotMarkers作爲實際數據點(即,不指定Mesh)。您可以使用自動PlotMarkers,或者您可以使用自定義PlotMarkers包括BoxWhisker標記來指示各種不確定性。

+1

這確實是做這件事的標準方式。但是,PlotLegend軟件包存在嚴重缺陷(請參閱http://stackoverflow.com/questions/3463437/plotting-legends-in-mathematica/3533152#3533152),另外,我覺得它有美學問題。 –

+0

@Sjoerd:我沒有注意到這個問題。 'PlotLegend'重新調整'Plot'的方式並不好... – Simon