MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg103431] Re: [mg103406] Overlaying List...Plots with other Plots?
  • From: "David Park" <djmpark at comcast.net>
  • Date: Mon, 21 Sep 2009 05:52:35 -0400 (EDT)
  • References: <521452.1253443525575.JavaMail.root@n11>

There is probably no single "proper" way but here is an example.

Let the following be a set of data points.

data = {{0.5, 2.15094}, {1., 2.39831}, {1.5, 2.61845}, {2., 
    2.60243}, {2.5, 2.83378}, {3., 3.13539}, {3.5, 3.54891}, {4., 
    3.60223}, {4.5, 4.13827}, {5., 4.56243}, {5.5, 4.92343}, {6., 
    5.35015}, {6.5, 6.01953}, {7., 6.27925}, {7.5, 6.63344}, {8., 
    7.04491}, {8.5, 7.96449}, {9., 8.26688}, {9.5, 9.81289}, {10., 
    9.91007}};

We find a fit to the data using the following model.

model = a + b x Exp[c x];
f[x_] = model /. FindFit[data, model, {a, b, c}, x]

A regular LogLogPlot is somewhat clumsy in that it requires Epilog and
different scales for the curve and the points. Furthermore, the scale for
the points does not correspond to the scale shown on the ticks. And finally,
the Automatic choice for the ticks and gridlines is probably not optimal.

LogLogPlot[f[x], {x, .5, 10},
 Epilog -> {AbsolutePointSize[3], 
   Point[{Log@First[#], Log@Last[#]}] & /@ data},
 Frame -> True,
 GridLines -> Automatic,
 GridLinesStyle -> GrayLevel[.85],
 ImageSize -> 300]

But naturally I would do it with Presentations.

Needs["Presentations`Master`"] 

The following is a basic set of graphics primitives for the data points and
the fitted curve.

basicgraphics = {Draw[f[x], {x, .5, 10}], AbsolutePointSize[3], 
   Point /@ data};

The following specifies log tick scales and log grid scales that can be used
in making all the various log/linear forms of the plot. In essence we have
to take the tick labeling and grids away from Mathematica and handle them
ourselves. With the Show statement you have to know how they are picked up
and be sure to put the correct plot first. 

xlogticks = 
  CustomTicks[Log10, {-1, 1, {1, 2, 5} // N, {3, 4, 6, 7, 8, 9}}];
xloggrids = 
  CustomGridLines[Log10, {-1, 1, Range[9]}, {GrayLevel[.85]}];
ylogticks = CustomTicks[Log10, {0, 1, {1, 2, 4, 6, 8}, {3, 5, 7, 9}}];
yloggrids = 
  CustomGridLines[Log10, {0, 1, Range[9]}, {GrayLevel[.85]}];

Then we make a LogLog plot just by using the Presentations DrawingTransform
rule to convert the basicgraphics to a LogLog form and then insert the ticks
and grid lines.

Draw2D[
 {basicgraphics /. DrawingTransform[Log10@#1 &, Log10@#2 &]},
 AspectRatio -> .8,
 PlotRangePadding -> Log10[10]/25,
 Frame -> True,
 FrameTicks -> {{ylogticks, ylogticks // NoTickLabels}, {xlogticks, 
    xlogticks // NoTickLabels}},
 GridLines -> {xloggrids, yloggrids},
 ImageSize -> 300]

It is easy to make other forms of the graphic. Here is a Log plot. We just
use a different DrawingTransform and top and bottom ticks.

Draw2D[
 {basicgraphics /. DrawingTransform[#1 &, Log10@#2 &]},
 AspectRatio -> .8,
 PlotRangePadding -> {.2, Log10[10]/25},
 Frame -> True,
 FrameTicks -> {{ylogticks, ylogticks // NoTickLabels}, {Automatic, 
    Automatic}},
 GridLines -> {Automatic, yloggrids},
 GridLinesStyle -> GrayLevel[.8],
 ImageSize -> 300]

In a sense this is more work because you have to specify what Mathematica
normally automatically chooses for you. But it is ultimately easier because
what if Mathematica doesn't choose the right thing, or what if you don't
even know how Mathematica is choosing things or how to control it?


David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/  


From: Erik Max Francis [mailto:max at alcyone.com] 

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?

Thanks.

-- 
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis
   I'll tell them that their daddy was / A good man
    -- India Arie




  • Prev by Date: Re: Capturing the output(s) from a Manipulate?
  • Next by Date: Re: Modifying Default Stylesheet?
  • Previous by thread: Re: Overlaying List...Plots with other Plots?
  • Next by thread: Re: Overlaying List...Plots with other Plots?