MathGroup Archive 2004

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

Search the Archive


  • To: mathgroup at
  • Subject: [mg45795] GridPlot
  • From: Selwyn Hollis <sh2.7183 at>
  • Date: Sun, 25 Jan 2004 03:04:49 -0500 (EST)
  • References: <>
  • Sender: owner-wri-mathgroup at

I've never much liked the way the GridLines option works in Plot. So 
for my own amusement I decided to try something different, and it 
turned into a nice exercise, I think. I thought some of you might be 
interested in the result, which is the following (rough) function named 
GridPlot. What it basically does is stretch automatically-generated 
tickmarks out to form grid lines. (The GridColor option lets you can 
change their color.)

GridPlot[f_, {x_, xmin_, xmax_}, opts___] :=
  Module[{a, b, c, d, grph, fullgrph, gridcolor},
    	gridcolor = GridColor /. {opts} /.
		{GridColor -> GrayLevel[0.85]};
     fullgrph = FullGraphics[grph = Plot[f, {x, xmin, xmax},
		DisplayFunction -> Identity,
     {{a, b}, {c, d}} = PlotRange /. AbsoluteOptions[grph];
     Show[ fullgrph /.{
	  {GrayLevel[0.], AbsoluteThickness[t_],
		 Line[{{u_,y1_},{u_,y2_}}]}/; (y2-y1<d-c) ->
        {gridcolor, AbsoluteThickness[t], Line[{{u,c},{u,d}}]},
	  {GrayLevel[0.], AbsoluteThickness[t_],
		Line[{{x1_,y_},{x2_,y_}}]}/; (x2-x1<b-a) ->
         {gridcolor, AbsoluteThickness[t], Line[{{a,y},{b,y}}]}
        grph, PlotRange -> {{a,b},{c,d}}, Axes -> True] ]

GridPlot[{1/x, Cos[x], Sin[x]}, {x, 0, 2Pi}]

Selwyn Hollis
(edit reply-to to reply)

  • Prev by Date: Re: Simple question or how Mathematica getting on my nerves.
  • Next by Date: Re: Simple question or how Mathematica getting on my nerves.
  • Previous by thread: Any way to display vars internal to a function on interrupt?
  • Next by thread: Re: GridPlot