0
$\begingroup$

I want to plot two functions in ONE plot, one given as an analytic expression, the other one is numeric.

How can I plot the analytic function continously and discrete points for the numeric function in the SAME plot?

$\endgroup$
3
  • 3
    $\begingroup$ Please post your data and function. Maybe by use Show $\endgroup$
    – cvgmt
    Commented Jan 26, 2021 at 11:25
  • 4
    $\begingroup$ If you want to plot the analytic function and add discrete points for the numeric function, you may do this using the option Epilogof Plot. If you want to plot both functions together, you may plot them separately (without displaying them) and then combine them using Show. $\endgroup$ Commented Jan 26, 2021 at 11:27
  • $\begingroup$ Show[Plot[f, {x, 0, 3}], ListPlot[data], PlotRange -> All]. If your numeric function is an interpolating function g over an interval, say {0, 3}, then Plot[{f, g[x]}, {x, 0, 3}] will do it, but it connect the interpolation data with a smooth interpolating curve; alternatively, using ListPlot[g] in the first code will plot the interpolation points without connecting them. $\endgroup$
    – Michael E2
    Commented Jan 30, 2021 at 18:27

1 Answer 1

3
$\begingroup$

Plot and DiscretePlot

Show[
 Plot[Fibonacci[n], {n, 0, 10}],
 DiscretePlot[
  Fibonacci[n], {n, 0, 10},
  PlotStyle -> Red]]

enter image description here

Plot and ListPlot

Show[
 Plot[Fibonacci[n], {n, 0, 10}],
 ListPlot[
  {#, Fibonacci[#]} & /@ Range[0, 10],
  PlotStyle -> Red,
  Filling -> Axis]]

Plot with Epilog

Plot[Fibonacci[n], {n, 0, 10},
 Epilog -> {LightRed,
   Line[{{#, 0}, {#, Fibonacci[#]}}] & /@ Range[0, 10],
   Red, AbsolutePointSize[4],
   Point[{#, Fibonacci[#]} & /@ Range[0, 10]]}]

Plot and Graphics

Show[
 Plot[Fibonacci[n], {n, 0, 10}],
 Graphics[{LightRed,
   Line[{{#, 0}, {#, Fibonacci[#]}}] & /@ Range[0, 10],
   Red, AbsolutePointSize[4],
   Point[{#, Fibonacci[#]} & /@ Range[0, 10]]}]]
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.