How to build function and data in Mathematica?

A simple question, but I can not find the answer.

I want to combine ListLinePlot and a regular chart (functions) into one chart. How to do it?

Thanks.

+4
source share
2 answers

Use Show , for example

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

Show output

Note that if plot parameters conflict, then Show uses the first plot parameter, if the parameter is not specified in Show. I.e.

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

shows a combined size chart of 100.

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

Shows a combined size chart of 300.

+11
source

An alternative to using Show and combining two separate graphs is to use Epilog to add data points to the main graph. For instance:

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

or

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

All Articles