MathGroup Archive 2009

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

Search the Archive

Plotting with dotted lines solved (Re: plotting with dotted lines, not dashed)

I put together a way to make proper dotted plots.  Thanks to everyone  
for the help, especially to Maxim whose e-mail helped me put together  
the solution below.

Just to review the issue:
- The PlotStyle option Dotted or Dashing[{0,r}] makes small  
(rectangular) dashes as opposed to circular dots.  This appears to be  
contrary to what the help file in 7.0.1 claims.
- Using ListPlot or using the Mesh and MeshStyle option in Plot  
produce unevenly spaced dots.

To produce a proper dotted plot, I defined the following function:
DotPlot[f_, x_, xrange_, yrange_, aspratio_, npts_, ptsize_, style_,  
opts_] :=
  Plot[f, {x, xrange[[1]], xrange[[2]]}, PlotRange -> {xrange, yrange},
    Mesh -> npts,
   MeshStyle -> Append[style, AbsolutePointSize[ptsize]],
   PlotStyle -> None, AspectRatio -> aspratio,
   MeshFunctions ->
    Function[{u, v},
     Sqrt[( u/(xrange[[2]] - xrange[[1]]))^2 +
       aspratio^2 (v/(yrange[[2]] - yrange[[1]]))^2]], opts]

The arguments should be self-explanatory.  For example, try
DotPlot[x/(1 + x), x, {0, 25}, {0, 1}, 1/GoldenRatio, 25, 5, {Blue}, {}]

Now compare the plot above to:
Plot[x/(1 + x), {x, 0, 25}, PlotStyle -> {Thick, Dotted},
  PlotRange -> {0, 1}]

ListPlot[Table[{x, x/(1 + x)}, {x, 0, 25}],
  PlotStyle -> {Blue, AbsolutePointSize[5]}, PlotRange -> {0, 1}]

The function DotPlot could be improved on, for example, if one could  
access PlotRange and AspectRatio inside the call to Plot (so that  
Automatic options could be used).  How would one access the local  
value of PlotRange or AspectRatio within a call to Plot?  I'm sure  
there's a way.

On Oct 28, 2009, at 4:08 AM, Robert Rosenbaum wrote:

> I need to plot a function with a dotted line for a figure to be
> published.  As you may know PlotStyle->Dotted simply makes a dashed
> line with small dashes.  Since I already have a dashed line in the
> figure, I would prefer an actual dotted line for this function.
> I tried ListPlot with PlotMarkers set to discs, but these get spaced
> according to the grid in the list I send to ListPlot.  In order to
> space them equally like Dashed does, I'd have to make a non-uniform
> grid that depends on the derivative of my function (which I don't have
> a closed form for).
> Surely there is a reasonable way to plot with a dotted line, right?
> Any ideas?
> Best,
> Robert


  • Prev by Date: Re: dynamicmodule with f[x_] possible?
  • Next by Date: Re: dynamicmodule with f[x_] possible?
  • Previous by thread: Re: Prufer Code/ LabeledTreeToCode Bug?
  • Next by thread: Re: Using Mathematica 5.2 and 7.01 with separate settings