2011-09-26 29 views
4

簡單的問題,但我找不到答案。如何在Mathematica中繪製函數和數據?

我想將一個ListLinePlot和一個常規Plot(一個函數的)組合到一個plot上。我該怎麼做呢?

謝謝。

+0

我確信,這個問題已經被問過這樣過,但無法找到它...的 – Simon

+4

可能重複[如何結合圖形ListPlot與繪圖的圖形?](http://stackoverflow.com/questions/6180373/how-do-i-combine-the-graphic-of-a-listplot-with-the-graphic-of- a-plot) – abcd

回答

11

使用Show,例如,

Show[Plot[x^2, {x, 0, 3.5}], ListPlot[{1, 4, 9}]] 

Show output

注意,如果情節選項衝突顯示使用第一個情節的選項,除非選項中顯示指定。即

Show[Plot[x^2, {x, 0, 3.5}, ImageSize -> 100], 
ListPlot[{1, 4, 9}, ImageSize -> 400]] 

顯示尺寸的組合曲線圖100

Show[Plot[x^2, {x, 0, 3.5}, ImageSize -> 100], 
ListPlot[{1, 4, 9}, ImageSize -> 400], ImageSize -> 300] 

顯示大小300

+0

正是我在找的東西!謝謝! – Nick

+0

@Chris Degnen有沒有辦法在WolframAlpha上做到這一點? http://www.wolframalpha.com/input/?i=Show[Plot[x^2%2C+{x%2C+0%2C+3.5}]%2C+ListPlot[{1%2C+4%2C+ 9}]]不起作用。 –

5

使用Show和組合兩個單獨曲線的另一種,是用Epilog到的組合曲線圖將數據點添加到主圖。例如:

data = Table[{i, Sin[i] + .1 RandomReal[]}, {i, 0, 10, .5}]; 
Plot[Sin[x], {x, 0, 10}, Epilog -> Point[data], PlotRange -> All] 

Plot[Sin[x], {x, 0, 10}, Epilog -> Line[data], PlotRange -> All] 
+0

謝謝!實際上,我在Mathematica幫助文件中看到了一個Point,但我沒有意識到你也可以使用Line來完成它! – Nick