f



Re: Overlaying List...Plots with other Plots?

On 9/20/09 at 6:23 AM, max@alcyone.com (Erik Max Francis) wrote:

>What's the smoothest way to draw a ListPlot (or its friends,
>ListLogPlot, ListLogLogPlot, etc.) with another plot of just a
>normal function (which is actually a curve fit to the data) on top
>of the ListPlot?

>I know that I can just do two plots (which are just Graphics objects
>anyway) and then show them simultaneously with show, but since it's
>a ListPlot, but since I'm dealing with an arbitrary set of data I
>don't know what the bounds of the plot will be, so I don't see how
>to easily choose the proper limits for the second Plot to Show
>together.

>I presume there must be a standard way of doing this since it's a
>pretty common operation; what's the "proper" way to do it?

I don't know that there is a standard way. And as for proper
way, I would say anything that yields the desired result can be
considered proper. In any case, here is one way

data = RandomReal[1, {10, 2}];
f = FindFit[data, m x + b , {m, b}, x];

Plot[m x + b /. f, {x, 0, 1}, Frame -> True, Axes -> None,
  Epilog -> {Point[data]},
  PlotRange -> {.95 Min@data[[All, 2]], 1.05 Max@data[[All, 2]]}]


0
readnews134 (1249)
9/21/2009 9:50:42 AM
comp.soft-sys.math.mathematica 28821 articles. 0 followers. Follow

1 Replies
667 Views

Similar Articles

[PageSpeed] 25

Bill Rowe wrote:
> I don't know that there is a standard way. And as for proper
> way, I would say anything that yields the desired result can be
> considered proper. In any case, here is one way
> 
> data = RandomReal[1, {10, 2}];
> f = FindFit[data, m x + b , {m, b}, x];
> 
> Plot[m x + b /. f, {x, 0, 1}, Frame -> True, Axes -> None,
>   Epilog -> {Point[data]},
>   PlotRange -> {.95 Min@data[[All, 2]], 1.05 Max@data[[All, 2]]}]

Thanks to everyone who responded with your suggestions.  A variant of 
this one looks like the best for my purposes, since I want to smoothly 
be able to support multiple plot types (Plot, LogPlot, etc.) without 
needing a carefully and completely constructed layout for each variant. 
  Plotting the curve fit _first_ and then using the Epilog option seems 
like the easiest approach.

-- 
Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis
   Can I be your friend / 'Till the end
    -- India Arie

0
max78 (1220)
9/22/2009 11:08:00 AM
Reply: