开发者

How do I combine the graphic of a ListPlot with the graphic of a Plot?

开发者 https://www.devze.com 2023-03-09 14:35 出处:网络
Is there a way to combine the graphic of a ListPlot to the graphic of a Plot? (I need t开发者_如何学编程o plot a graphic of a function on the graphic of a ListPlot)You can combine any graphics with th

Is there a way to combine the graphic of a ListPlot to the graphic of a Plot? (I need t开发者_如何学编程o plot a graphic of a function on the graphic of a ListPlot)


You can combine any graphics with the Show function like so:

Show[myListPlot, myPlot]

This generalizes to combining any number of plots at once: Show[p1, p2, p3, p4, ...] or Show[{p1,p2,p3,p4,...}]


Reference and image source: http://reference.wolfram.com/mathematica/ref/Show.html

How do I combine the graphic of a ListPlot with the graphic of a Plot?

How do I combine the graphic of a ListPlot with the graphic of a Plot?


You can use Epilog as well if Show is not stacking the graphics in the correct order, but combining more than 2 graphics with Epilog will be unwieldy.


From your second line, I think Epilog is what you are looking for. Here's an example:

f[x_] := 1/Sqrt[2 Pi] Exp[-(x^2)/2];
ListPlot[
 Table[
  {x, PDF[NormalDistribution[], x]}, {x, -4, 4, 0.1}
  ],
 Epilog -> First@Plot[f[x], {x, -4, 4}, PlotStyle -> Red]
 ]

How do I combine the graphic of a ListPlot with the graphic of a Plot?

Another way to do the same would be to use Show

p1 = ListPlot[
   Table[
    {x, PDF[NormalDistribution[], x]}, {x, -4, 4, 0.1}
    ]
   ];
p2 = Plot[f[x], {x, -4, 4}, PlotStyle -> Red];
Show[p1,p2]

On the other hand, if I was mistaken and you just wanted to combine them in the sense one next to the other, then you can use GraphicsRow or GraphicsColumn.

FullGraphics@GraphicsRow[{p1, p2}]

How do I combine the graphic of a ListPlot with the graphic of a Plot?

0

精彩评论

暂无评论...
验证码 换一张
取 消